My script downloads files from the net and then it saves them under the name taken from the same web server. I need a filter/remover of invalid characters for file/folder names under Windows NTFS.
I would be happy for multi platform filter too.
NOTE: something like htmlentities would be great….
Like Geo said, by using
gsubyou can easily convert all invalid characters to a valid character. For example:You need to replace
<invalid characters>with all the possible characters that your file names might have in them that are not allowed on your file system. In the above code each invalid character is replaced with a_.Wikipedia tells us that the following characters are not allowed on NTFS:
So your
gsubcall could be something like this:which replaces all the invalid characters with an underscore.