Remove bad characters for a server.mappath path string

elrond

New Member
I have an old classic ASP script which uses the \[code\]FileSystemObject\[/code\] to loop through a list of folders.Every now and then the script fails because the system found an invalid character in the \[code\]Server.MapPath\[/code\] path string. In my case it's a comma. I went on to read about this problem and it turns out there are a few characters that cause a \[code\]Server.MapPath\[/code\] to fail, which is annoying because most of them are valid file path characters in Windows. They are:\[code\]CHR(0) CHR(9) CHR(10) CHR(11) CHR(12) CHR(13) CHR(32) CHR(38) & CHR(34) " CHR(42) * CHR(44) , CHR(58) : CHR(60) < CHR(62) > CHR(63) ? CHR(160)\[/code\]Now, instead of me writing 16 individual replace functions:\[code\]For Each folder In Folder folder.name = Replace(folder.name , "," , "") folder.name = Replace(folder.name , ":" , "") ... path = Server.MapPath("../../folders/"&folder.name&"/")Next\[/code\]Is there a more elegant or proper way of doing this, perhaps with RegEx?
 
Back
Top