File Finder Utility
Uma utilitário Python para encontrar e gerenciar arquivos baseado em padrões de nome e data de modificação.
Descrição
Este pacote fornece funções para busca inteligente de arquivos em diretórios, permitindo localizar o arquivo mais recente que corresponda a um padrão específico no nome.
Instalação
Clone o repositório
git clone https://github.com/phadias/file-finder-utility.git
cd file-finder-utility
Ou instale diretamente via pip
pip install file-finder-utility
Exemplos Práticos
import os
from file_finder import check_last_file
# Encontrar o último backup
backup_path = check_last_file('/var/backups', 'system_backup')
# Encontrar o último relatório gerado
relatorio_path = check_last_file('./relatorios', 'vendas')
# Trabalhar com o arquivo retornado
if backup_path.exists():
print(f"Último backup: {backup_path.name}")
print(f"Tamanho: {backup_path.stat().st_size} bytes")
API Reference
check_last_file(path_file: str, ref: str) -> Path
Encontra o arquivo mais recente em um diretório que contenha a referência especificada.
Parâmetros:
-
path_file (str): Caminho do diretório onde será realizada a busca
-
ref (str): String de referência que deve estar contida no nome dos arquivos
Retorna:
- Path: Objeto Path do arquivo mais recente que contém a referência
Raises:
ValueError: Se nenhum arquivo for encontrado com a referência especificada
FileNotFoundError: Se o diretório especificado não existir
Exemplos de Casos de Uso
- Monitoramento de Backups
def verificar_ultimo_backup():
try:
ultimo_backup = check_last_file('/backups', 'database')
print(f"Último backup encontrado: {ultimo_backup}")
return ultimo_backup
except ValueError:
print("Nenhum backup encontrado!")
return None
- Processamento de Relatórios
def processar_relatorio_mais_recente():
relatorio = check_last_file('./relatorios', 'vendas_diarias')
# Processar o relatório mais recente
with open(relatorio, 'r') as file:
dados = file.read()
# ... processamento dos dados
- Limpeza de Arquivos Temporários
def manter_apenas_ultimo_arquivo():
arquivos = list(Path('./temp').glob('*log*'))
if len(arquivos) > 1:
mais_recente = check_last_file('./temp', 'log')
for arquivo in arquivos:
if arquivo != mais_recente:
arquivo.unlink() # Remove arquivos antigos
Requisitos
Python 3.7+pathlib(incluído na biblioteca padrão do Python)os(incluído na biblioteca padrão do Python)
Estrutura do Projeto
file-finder-utility/
└── file_finder/
│ ├── __init__.py
│ └── core.py
├── LICENSE
├── requirements.txt
├── setup.py
└── README.md
Desenvolvimento
# Clonar e configurar
git clone https://github.com/seu-usuario/file-finder-utility.git
cd file-finder-utility
# Criar ambiente virtual
python -m venv venv
source venv/bin/activate # Linux/Mac
# ou
venv\Scripts\activate # Windows
# Instalar dependências de desenvolvimento
pip install -r requirements.txt
Dicas de Uso
-
A busca é case-sensitive (diferencia maiúsculas de minúsculas)
-
Use
*curingas no parâmetrorefpara buscas mais flexíveis -
A função considera a data de modificação do arquivo, não a data de criação
Changelog
v0.0.1
-
Funcionalidade inicial: check_last_file
-
Suporte para busca por padrões em nomes de arquivos
-
Retorno do arquivo mais recente baseado na data de modificação
Licença
Este projeto está licenciado sob a Licença MIT - veja o arquivo
para detalhes:
Metadata
Release files for file-finder-utility 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| file_finder_utility-0.0.1.tar.gz | 5.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| file_finder_utility-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.9 kB
Release files / file_finder_utility-0.0.1.tar.gz
| Download URL | file_finder_utility-0.0.1.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aa3b325036a88294396e4620a7cc6d9eee3637fc78e041e1bf2ba733cef1cf38
|
|
BLAKE2b-256 checksum How to use checksums |
852dfd7e662902da11e45000c76d416cc74a951f76d83eda119feba4a88736d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Release files / file_finder_utility-0.0.1-py3-none-any.whl
| Download URL | file_finder_utility-0.0.1-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
401abe1ca27c97b7ed9b7af417661b975e1a3aaa46897ee8893025588326b269
|
|
BLAKE2b-256 checksum How to use checksums |
7a07d32cfd4e2269e0aa14e7524fd0c42f7f4d9e7c96ed02b9b35dd4054a7228
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Security for file-finder-utility 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.