Add a Date to Filenames

In a world where keeping track of documents is paramount to success, you find yourself in the role of a software developer for a historical archive. As they digitalize their thousands of documents, it becomes apparent that the naming of the files lacks consistency and the dates when the documents were originally created are not apparent from the file names. Your task is to create a Python script that can add a date to the filename of each document in a specified directory to keep a record of their original creation date.
The first line of the input contains a date in the format YYYY-MM-DD. The second line contains a directory path. Your script should rename all files in the given directory by adding the given date at the beginning of each filename. The date and the original filename should be separated by an underscore _.
The output of the program should contain a list of the renamed files. Each line should represent a file and should contain the new filename.
2023-07-24 path/to/directory
2023-07-24_file1.txt 2023-07-24_file2.txt 2023-07-24_image.jpg 2023-07-24_document.pdf


Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue