python 3.x - Renaming file right after download and moving it to new folder -
i have script downloads file site , saved downloads folder. want change name of file , move new folder. have code generates new filename, i'm not sure how take effect. have:
newfile_name='generated user input' os.listdir("c:\users\qzh14\downloads") os.rename("originalfile","newfile_name") shutil.move("currentfolder", "newfolder")
i'm not sure if that's full code, use rename method of os.
import os mypath = "mydir/myfolder" new_name = input("what's new name? ") # assuming have 1 file in dir old_name = os.listdir(mypath) #create new folder in current dir new_path = mypath + "newfolder" # not sure created new folder, i'm using method create 1 os.renames(old_name, (new_path + "/" + new_name))
tell me if i've missed anything. i'm relatively new python i've been doing similar work. hope helps :)
update: searching file if want select file available files, can @ files there manually enter file want. this:
in_folder = os.listdir(mypath) print(in_folder) old_name = input("which of these files? ")
Comments
Post a Comment