I need to sequentially rename batch files by sorting them according to their creation date and time. The first name should be started from 1001 and it should be increase by 1. To do this I have got a sample code from https://www.geeksforgeeks.org/rename-multiple-files-using-python
It renames filenames randomly. But I need to do it according to file creation date and time. How can I do it?
If anyone suggest VBScript or PowerShell it will be also highly appreciated.
import os
def main():
folder = "xyz"
for count, filename in enumerate(os.listdir(folder)):
dst = f"1001{str(count)}.jpg"
src = f"{folder}/{filename}" # foldername/filename, if .jpg file is outside folder
dst = f"{folder}/{dst}"
os.rename(src, dst)
# Driver Code
if __name__ == '__main__':
main()
Advance thanks for your help.
Best regards