How do I move a file in Python?

os.rename(), os.replace(), or shutil.move() All employ the same syntax: import os import shutil os.rename(“path/to/current/file.foo”, “path/to/new/destination/for/file.foo”) os.replace(“path/to/current/file.foo”, “path/to/new/destination/for/file.foo”) shutil.move(“path/to/current/file.foo”, “path/to/new/destination/for/file.foo”) The filename (“file.foo”) must be included in both the source and destination arguments. If it differs between the two, the file will be renamed as well as moved. The directory within which the new file is … Read more

How to move a file in Python?

os.rename(), os.replace(), or shutil.move() All employ the same syntax: import os import shutil os.rename(“path/to/current/file.foo”, “path/to/new/destination/for/file.foo”) os.replace(“path/to/current/file.foo”, “path/to/new/destination/for/file.foo”) shutil.move(“path/to/current/file.foo”, “path/to/new/destination/for/file.foo”) Note that you must include the file name (file.foo) in both the source and destination arguments. If it is changed, the file will be renamed as well as moved. Note also that in the first two … Read more