Created
June 25, 2025 21:16
-
-
Save me-suzy/19c4aa35747da643d7bb99846c8b00be to your computer and use it in GitHub Desktop.
Copiaza in folderul 3 din partitia D fisierele mobi sau alte formate in afara de PDF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import shutil | |
import time | |
# Source and destination directories | |
source_dir = r"g:\ARHIVA\A" | |
dest_dir = r"d:\3" | |
# Ensure destination directory exists | |
os.makedirs(dest_dir, exist_ok=True) | |
# List of preferred file extensions in order | |
preferred_extensions = ['mobi', 'epub', 'djvu', 'docx', 'doc', 'rtf'] | |
# Recursively iterate through all subfolders | |
for root, dirs, files in os.walk(source_dir): | |
# Check if there are any PDF files in the current directory | |
has_pdf = any(f.lower().endswith('.pdf') for f in files) | |
if not has_pdf: | |
# Look for files in the preferred order | |
for ext in preferred_extensions: | |
for file in files: | |
if file.lower().endswith(f'.{ext}'): | |
source_file = os.path.join(root, file) | |
dest_file = os.path.join(dest_dir, file) | |
# Display file being processed | |
print(f"Processing: {file} from {root}") | |
# Copy file, overwriting if it exists | |
shutil.copy2(source_file, dest_file) | |
# Display file copied | |
print(f"Copied: {file} to {dest_dir}") | |
break | |
else: | |
continue | |
break | |
else: | |
print(f"No supported files found in {root}") | |
time.sleep(0.1) # Small delay for visibility |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment