thombashi / pathvalidate

A Python library to sanitize/validate a string such as filenames/file-paths/etc.
https://pathvalidate.rtfd.io/
MIT License
210 stars 12 forks source link

/Users/ken/duptemp/foo and others are invalid filenames. What? #33

Closed kwloafman closed 1 year ago

kwloafman commented 1 year ago

On macOS 12.6.6. Basically, it's marking anything with a leading '/' as invalid.

$ ipython
Python 3.11.3 (main, Apr  7 2023, 19:29:16) [Clang 14.0.0 (clang-1400.0.29.202)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.13.2 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import pathvalidate as pv

In [2]: pv.is_valid_filepath('/Users/ken/duptemp/foo')
Out[2]: False

In [3]: pv.is_valid_filepath('~/duptemp/foo')
Out[3]: True

In [4]: pv.is_valid_filepath('bar/zot')
Out[4]: True

In [5]: pv.is_valid_filepath('/bar/zot')
Out[5]: False
thombashi commented 1 year ago

That is because platform argument defaults to "universal". universal means that check if the file path is usable on any OS. File paths starting with / is invalid for Windows. The return value will be True if you set platform keyword argument value for any of "auto", "POSIX", "macOS".