pythonunicodewindowserror

Python pathlib glob function fails on WindowsError: [123]?


I've written the following python function that returns a python list of File Geodatabase Paths. Please note that input_folder is a raw string and contains no unicode characters.

try:
    gdbs = list(Path(input_folder).glob('**/*.gdb'))
    for gdb in gdbs:
        print(gdb)
except WindowsError, e:
    print("error")

The problem that I'm having is that pathlib glob method is failing when it encounters unicode characters in the path of files in the directory.

I tried the following but it still fails, which I assume is because I'm not converting the paths the glob generator is coming across.

try:
    gdbs = list(Path(unicode(input_folder)).glob('**/*.gdb'))
    for gdb in gdbs:
        print(gdb)
except WindowsError, e:
    print("error")

The error message that is returned is:

WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: 'R:\\Data\\Africa\\Tanzania\\fromDropbox\\DART\\BRT Phase 2-3 designs\\1.12 Engineering Drawings for Service\\ROAD LIGHT\\PDF\\01.Traffic Sign(Kilwa)-??04.pdf'

Any help to handle the following error will be appreciated.


Solution

  • It seems to be a problem with pathlib because of Python 2.7 not being able to handle non-ascii characters. pathlib chokes up on international characters on Python 2 on Windows