0

I'm using glob to walk through a directory, and pull files that fit a particular parameter. The trouble I'm running into is a FileNotFoundError partway through the glob:

def collate_files(old_dir, new_dir) -> str:
   for subfolder in old_dir.rglob('*.xlsx'):  
       if subfolder.match("string_title"):
           new_dir= new_dir.joinpath(subfolder)
           if Path.exists(new_dir):
               pass
           else:
               try:
                   shutil.copy(subfolder, new_dir, follow_symlinks=True)
               except OSError as e:
                   raise e

Error comes up as:

FileNotFoundError: [WinError 3] The system cannot find the path specified: "\\\\absoute_path_directory\\subfolder\\etc"

I double checked, and the file path exists. What can I do to either fix the OSError or pass over it entirely?

Tfmgvi_971
  • 81
  • 7

1 Answers1

1

This might be an issue of your file path length? Regular DOS paths are limited to MAX_PATH (260) characters. So you might have a look on the links below to get in detailed. The best way would be, to activate a long path support within glob. But I don't know how to do this.

Pathname too long to open?

os.stat FileNotFoundError [Win Error 3] when file exist. (Python)

Lama
  • 83
  • 7