Hi,
A wrote a script that moves files into folders according to the files creation time, but I could not figure out how to add a leading zero to the folders name. I'd like it this way: 2017-01-18, not 2017-1-18.
I also wanted the first argument to be the folder path on which folder the script should run, i tried this at the beginning:
Thanks
Zoli
A wrote a script that moves files into folders according to the files creation time, but I could not figure out how to add a leading zero to the folders name. I'd like it this way: 2017-01-18, not 2017-1-18.
import os, time, shutil os.chdir('.') for f in os.listdir('.'): file_creation_time = time.gmtime(os.path.getmtime(f)) dir_creation_time = str(file_creation_time.tm_year) + '-' + str(file_creation_time.tm_mon) + '-' + str(file_creation_time.tm_mday) if not os.path.isdir(dir_creation_time): os.mkdir(dir_creation_time) if '.py' in f: continue else: try: shutil.move(f, dir_creation_time) except: passAnd I'd like a more elegant way of excluding the the script, but sys.argv[0] returns the full path, but I only need the script name.
I also wanted the first argument to be the folder path on which folder the script should run, i tried this at the beginning:
dir = sys.argv[1] os.chdir(dir)But it didn't work. I'd really like to invoke the script by cron, with an argument on which folder should it run...
Thanks
Zoli