Is there a function I can use that converts dodgy filenames with good filenames?
I’m processing a large amount of photos, and very occasionally, my script stops because the uploader has put a curly symbol (~) in the filename. I’m also now wondering if there are any other bad symbols that can’t be in a filename and how to escape them.
I’m looping through these files using VBScript’s FileSystem Object, similar to the following:
For Each File In Files
If InStr(UCase(File.Name), ".JPG") > 0 Then
'// do stuff
End If
Next
You can make a function that will return a ‘cleaned’ filename like:
And replace the name of the file with the cleaned one. Becomes risky when you have two files that are only unique on the special characters.
Above is the ‘whitelist’ variant, if you prefer a ‘blacklist’ version, you can replace the pattern for something like
[~!@#$%^&()]