简体   繁体   中英

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.

Try this :

input_folder = r'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'

The correct call should have 'r' in front of the path, and using single slash.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM