Python ZIp Assignment
Python ZIp Assignment
--------------------------------------------------------------------------------------------
Program-1 Renaming files from American-style dates to European-style
Main program
import os
import re
import shutil
# Extract parts
before = match.group("before")
month = match.group("month").zfill(2)
day = match.group("day").zfill(2)
year = match.group("year")
after = match.group("after")
# Full paths
old_path = os.path.join(folder_path, filename)
new_path = os.path.join(folder_path, european_filename)
After
The program converts the file names with American style date to
European style dates
1. Sets a target folder (test_file) where files are located.
2. Defines a regex pattern to find filenames containing American-
style dates (MM-DD-YYYY).
3. Loops through all files in the target folder.
4. For each file, checks if the filename matches the American date
pattern.
5. If matched, extracts the date parts (month, day, year) and
surrounding text.
6. Converts the date format from American (MM-DD-YYYY) to
European (DD-MM-YYYY).
7. Constructs a new filename with the converted date format.
8. Prints out the intended rename operation (old filename → new
filename).
9. If dry_run is set to False, actually renames the files on disk using
shutil.move.
10. Otherwise, if dry_run is True, it only simulates the rename
by printing.
Program-2 Backing up a folder into a zip file.
Main program
Output
Before Executing
After Executing