flickr-download
flickr-download copied to clipboard
Convert set and photo names to valid filenames
To avoid exceptions when creating directories and saving files, only valid filenames should be used. For portability reasons Windows filename restrictions are enforced: https://stackoverflow.com/a/31976060/25450
Reserved characters are replaced with an underscore '_'. Trailing whitespace and dots are removed. Reserved filenames (like COM or NUL) are prefixed with an underscore.
Thanks for the PR! I have a few code comments which I will add in a bit. But is there really not built in way to do this in Python? Ugh. As much as I hate operating system specific code, let's at least only do it on Windows. There is no reason to change the filename on other operating (/file) systems with less restrictions.
I implemented the changes, mostly as you asked. I moved regular expressions to the global scope. So the same compiled expressions can be reused most of the time.
But is there really not built in way to do this in Python?
Not that I know of.
There is no reason to change the filename on other operating (/file) systems with less restrictions.
For a long time I was doing all my photo management in Linux, and eventually I found that it's better to follow the most restrictive file naming conventions, because sooner or later there might be a need to copy files to a Windows filesystem. Basically, just avoiding <
, >
, "
, :
, slashes, *
, ?
, and |
in the filenames makes any archive much more portable.
If you want I may add platform detection checks, but if I were you I would keep the script as simple as possible and choose only one behavior for all platforms.
you might also want to treat filenames and directories differently
According to Microsoft docs, naming rules are the same for filenames and directories.
Sorry, this got lost.
I implemented the changes, mostly as you asked. I moved regular expressions to the global scope. So the same compiled expressions can be reused most of the time.
But is there really not built in way to do this in Python?
Not that I know of.
Kind of crazy.
There is no reason to change the filename on other operating (/file) systems with less restrictions.
For a long time I was doing all my photo management in Linux, and eventually I found that it's better to follow the most restrictive file naming conventions, because sooner or later there might be a need to copy files to a Windows filesystem. Basically, just avoiding
<
,>
,"
,:
, slashes,*
,?
, and|
in the filenames makes any archive much more portable.If you want I may add platform detection checks, but if I were you I would keep the script as simple as possible and choose only one behavior for all platforms.
I am in favor of platform detection. No reason to limit users on all operating systems because of one platform's restrictions.
you might also want to treat filenames and directories differently
According to Microsoft docs, naming rules are the same for filenames and directories.
Ok. As long as it's platform specific, then all good.
I added https://pypi.org/project/pathvalidate/ a while back