z230
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
"""
|
||||
Přesune soubory z Downloads Z230 do #Trash/YYYY-MM-DD,
|
||||
kromě FIO transactions a DropboxBackupReport.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import shutil
|
||||
from datetime import date
|
||||
from pathlib import Path
|
||||
|
||||
# Přidá kořen projektu do sys.path, aby šlo importovat Knihovny
|
||||
_PROJEKT = Path(__file__).resolve().parents[2] # ordinaceprojekt/
|
||||
sys.path.insert(0, str(_PROJEKT))
|
||||
|
||||
from Knihovny.najdi_dropbox import get_dropbox_root
|
||||
|
||||
_DROPBOX = Path(get_dropbox_root())
|
||||
SOURCE_DIR = _DROPBOX / "!!!Days" / "Downloads Z230"
|
||||
TRASH_DIR = SOURCE_DIR / "#Trash"
|
||||
|
||||
IGNORE_PATTERNS = [
|
||||
"FIO transactions.xlsx",
|
||||
"DropboxBackupReport.xlsx",
|
||||
]
|
||||
|
||||
|
||||
def should_ignore(filename: str) -> bool:
|
||||
for pattern in IGNORE_PATTERNS:
|
||||
if filename.endswith(pattern):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
today = date.today().strftime("%Y-%m-%d")
|
||||
dest_dir = TRASH_DIR / today
|
||||
|
||||
files_to_move = [
|
||||
f for f in SOURCE_DIR.iterdir()
|
||||
if f.is_file() and not should_ignore(f.name)
|
||||
]
|
||||
|
||||
if not files_to_move:
|
||||
print("Žádné soubory k přesunu.")
|
||||
return
|
||||
|
||||
dest_dir.mkdir(parents=True, exist_ok=True)
|
||||
print(f"Cíl: {dest_dir}")
|
||||
|
||||
for f in files_to_move:
|
||||
target = dest_dir / f.name
|
||||
if target.exists():
|
||||
base = f.stem
|
||||
suffix = f.suffix
|
||||
i = 1
|
||||
while target.exists():
|
||||
target = dest_dir / f"{base} ({i}){suffix}"
|
||||
i += 1
|
||||
shutil.move(str(f), str(target))
|
||||
print(f" {f.name} → {target.name}")
|
||||
|
||||
print(f"\nPřesunuto {len(files_to_move)} souborů.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user