I'm confused with file moving under python. Under windows commandline, if i have directory c:\a and a directory c:\b, i can do
move c:\a c:\b
which moves a to b result is directory structure c:\b\a
If I try this with os.rename or shutil.move:
os.rename("c:/a", "c:/b")
I get
WindowsError: [Error 17] Cannot create a file when that file already exists
If I move a single file under c:\a, it works.
In python how do i move a directory to another existing directory?
Python provides functionality to move files or directories from one location to another location. This can be achieved using shutil. move() function from shutil module.
The Python shutil. move() method moves a file to another location on your computer. This method is part of the shutil model, which you must import before using this method.
os.rename("c:/a", "c:/b/a")
is equivalent to
move c:\a c:\b
under windows commandline
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With