Python: Finding user id and moving directories (Windows)

后端 未结 2 1589
不知归路
不知归路 2021-01-27 11:37

What I\'m trying to accomplish is to have my program move itself from the folder it\'s currently in, to another folder. In this case, Videos. This is the code:

i         


        
2条回答
  •  生来不讨喜
    2021-01-27 12:13

    os.rename("$s/userid.py", "%s/Videos/userid.py")  % ('os.getcwd()', '%userid')
    

    %userid will only give you userid, you need to specify the full path. Also note $s you have used, it should instead be %s.

    Please note both the directories should exist beforehand. While the file in the destination directory shouldn't.

    Also you can use the shutil.move() for the same.

提交回复
热议问题