Until today, i was using one quite slow function to replace the unsupported characters in file name (* ? \ / | : < > "), and not just replace them, but also to insure that the replaced chars will not been repeated...
This is the Old function (uses loop to strip repeating chars):
Func ReplaceUnsupported($String, $Patern='[*?\\/|:<>"]', $Replace="_") If StringLen($String) = 0 Then Return $String $String = StringRegExpReplace($String, $Patern, $Replace) While StringInStr($String, $Replace & $Replace) <> 0 $String = StringReplace($String, $Replace & $Replace, $Replace) WEnd Return $String EndFunc
And this one is New function + usage example (it's uses a genius RegExp engine
#include <Date.au3> $sFileName = _Now() & "_File.txt" $sFileName = _FileGetValidName($sFileName, '[*?\\/|:<>"]', '_') ConsoleWrite("Replacements: " & @extended & @CRLF & "Result: " & $sFileName) ;Will output something like this: ; Replacements: 2 ; Result: 19.01.2009 4_15_59_File.txt Func _FileGetValidName($sString, $sPatern='[*?\\/|:<>"]', $sReplace='_') If StringStripWS($sString, 8) = '' Then Return $sString $sString = StringRegExpReplace($sString, $sPatern, $sReplace) Return SetExtended(@extended, StringRegExpReplace($sString, '(' & $sReplace & '+)', $sReplace)) EndFunc
I hope that someone will find it usefull
Edited by MrCreatoR, 12 June 2009 - 10:04 AM.









