Good Day
I am trying to create a program that copies the newest file in a folder to another folder using Python 2.7. I have been able to copy a specified file using the following code:
def copy():
# copies actual file
shutil.copy(input, output)
print(copy())
However I need to identify the newest file(Date Created) within the folder and copy that file to the new folder.
I have been able to extract the filename and the date created of a specific file using the following code:
def copy():
# variables for copying
input = r"C:\Users\micha\Desktop\Test_Copy1\Test1.txt"
output = r"C:\Users\micha\Desktop\Test_Copy2"
path = r"C:\Users\micha\Desktop\Test_Copy1"
h ="C:\Users\micha\Desktop\PythonTools\Test1.txt"
# copies actual file
# shutil.copy(input, output)
timestamp = os.path.getctime(input)
convert = datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
name = os.path.basename(input)
print name
print convert
print(copy())
However I am unsure as to how I would perform this analysis on all the files within a folder and then identifying the right file to copy to the new folder.
If anyone could help it would be much appreciated.