The program should copy all files from the current directory and all subdirectories.

At startup, the program worked and copied 42 of 299 files and issued the following error:

--------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) <ipython-input-2-40d66524ed3e> in <module>() ----> 1 copy_files(r'C:\Users\Dmytro\Desktop\map') <ipython-input-1-fbaa373faa32> in copy_files(folder) 7 for currentFolder, subFolders, fileNames in os.walk(folder): 8 for i in fileNames: ----> 9 shutil.copy(currentFolder+'\\'+i, r'C:\Users\Dmytro\Desktop\Folder') ~\Anaconda3\lib\shutil.py in copy(src, dst, follow_symlinks) 239 if os.path.isdir(dst): 240 dst = os.path.join(dst, os.path.basename(src)) --> 241 copyfile(src, dst, follow_symlinks=follow_symlinks) 242 copymode(src, dst, follow_symlinks=follow_symlinks) 243 return dst ~\Anaconda3\lib\shutil.py in copyfile(src, dst, follow_symlinks) 118 os.symlink(os.readlink(src), dst) 119 else: --> 120 with open(src, 'rb') as fsrc: 121 with open(dst, 'wb') as fdst: 122 copyfileobj(fsrc, fdst) FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Dmytro\\Desktop\\map\\LOFT APARTMENT -share by QKK\\qwe]\\LOFT APARTMENT LIVINGROOM-by QKK\\map\\30.5.17\\30.05.17\\SCAN CRN sua\\chua loc 1.9\\New folder (6)\\New folder\\20150702_Livingroom_Corona_4pixosGIFTscene\\20150120 Interior Design\\MAX\\MAP\\GlassEtchings.jpg' 

Although the file itself and the directory exist, otherwise the walk module has learned about them.

I decided to make a check on the existence of the directory and the file and about the miracle before copying, the program worked without errors, but copied 255/299 files, how so and why some directories and files do not see?

The program itself:

 import shutil import os def copy_files(folder): '''Copy all files in current Folder and sub Folder''' for currentFolder, subFolders, fileNames in os.walk(folder): for i in fileNames: if os.path.isdir(currentFolder) and os.path.isfile(currentFolder+'\\'+i): shutil.copy(currentFolder+'\\'+i, r'C:\Users\Dmytro\Desktop\Folder') 
  • Welcome to Stack Overflow in Russian! text information is better to attach as text: a) easier to read; b) can be copied; c) the search works. You can correct the question text by clicking below to edit the question text - aleksandr barakin
  • one
    260 bytes of the full name - bust hike. - Akina
  • docs.microsoft.com/en-us/windows/desktop/FileIO ... It is very likely that your path is too long. - nick_gabpe
  • That's right, way too long. Thanks - dmytro

0