Reputation: 23
I am trying to move specific folders within a file directory inside a flash drive with the Python shutil
library. I am getting the following error:
FileNotFoundError: [Errno 2] No such file or directory: 'D:\\New Folder\\CN00020'.
I have looked at some questions posted and I think my issue may be that I am not declaring the filepath correctly. I am using the Spyder app for Python and Windows 10.
import shutil
shutil.move('D:\\New Folder\CN00020', 'D:\\Batch Upload')
Upvotes: 2
Views: 204
Reputation: 56
the problem is that \
has special meaning. Python interprets \C
as a special character. There are three solutions:
# escape backspace
shutil.move('D:\\New Folder\\CN00020', 'D:\\Batch Upload')
# use raw strings
shutil.move(r'D:\New Folder\CN00020', r'D:\Batch Upload')
# use forward slashes which shutil happens to support
shutil.move('D:/New Folder/CN00020', 'D:/Batch Upload')
Upvotes: 4