 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
kiwijunglist
Joined: 26 May 2009 Posts: 8
|
Posted: Tue Dec 22, 2009 11:11 pm Post subject: Convert text string to acceptable filename format |
|
|
Hi
Is there an existing function / script that will convert a text string containing extended characters into a text string that complies with windows filename formating standards?
(I wasn't able to find one by searching the forums)
Thanks
Mike |
|
| Back to top |
|
 |
Micahs
Joined: 01 Dec 2006 Posts: 460
|
Posted: Wed Dec 23, 2009 9:06 am Post subject: |
|
|
One thing I can think of that is really simple is
| Code: | ;replace any chars that are not "a-zA-Z0-9_" with underscore
txt := RegExReplace(txt, "\W", "_")
| If your text contains only extended chars, you might want another solution, though, because there won't be anything left but underscores! _________________
 |
|
| Back to top |
|
 |
kiwijunglist
Joined: 26 May 2009 Posts: 8
|
Posted: Wed Dec 23, 2009 12:53 pm Post subject: |
|
|
Thanks Micahs.
What about replacing an extended character?
eg. Replace all â with a
txt := RegExReplace(txt, "â", "a") |
|
| Back to top |
|
 |
SoLong&Thx4AllTheFish
Joined: 27 May 2007 Posts: 4999
|
Posted: Wed Dec 23, 2009 1:01 pm Post subject: |
|
|
| Code: | txt=âáä
MsgBox % RegExReplace(txt, "â|á|ä", "a") ; or use [âáä]
; Or use a loop
txt=âáäéë
replace=âa|áa|äa|ée|ëe
Loop, Parse, Replace, |
{
StringSplit, Part, A_LoopField
StringReplace, txt, txt, %Part1%, %Part2%, All
}
MsgBox % txt |
_________________ AHK Wiki FAQ
TF : Text files & strings lib, TF Forum |
|
| Back to top |
|
 |
kiwijunglist
Joined: 26 May 2009 Posts: 8
|
Posted: Wed Dec 23, 2009 1:08 pm Post subject: |
|
|
Thank you both very much.
So I can use the Loop method, then use the "/W" to replace anything i have missed.
So the final code would be
| Code: |
txt=mïchâël©
;replace ïâë -> iae
replace=ïi|âa|ëe
Loop, Parse, Replace, |
{
StringSplit, Part, A_LoopField
StringReplace, txt, txt, %Part1%, %Part2%, All
}
;replace any chars that are not "a-zA-Z0-9_" with underscore
txt := RegExReplace(txt, "\W", "_")
|
|
|
| Back to top |
|
 |
Guest
|
Posted: Wed Dec 23, 2009 10:50 pm Post subject: |
|
|
| Quote: | Not sure what OS you guys are using, but this is the official Microsoft answer:
Use any character in the current code page for a name, including Unicode characters and characters in the extended character set (128–255), except for the following:
* The following reserved characters: < > : " / \ | ? *
* Integer value zero, sometimes referred to as the ASCII NUL character.
* Characters whose integer representations are in the range from 1 through 31, except for streams where these characters are allowed.
* Any other character that the target file system does not allow.
The only obvious conversion into filename problem are the :, / and ? chars that are used in certain titles (have never seen any other of the reserved ones, unless somebody can point them out, actually scratch that, I just remembered movie "Bat*21").
So "Star Wars; Episode III - Revenge of the Sith [2005].mkv", "Æon Flux [2005].mkv" and "Vi på Väddö [1958].avi" are perfect valid filenames. The only reason I sometimes do not use those weird characters is when the auto-approve rate declines from it.
My personal replacement list is as follows:
* : = ;
* / = _
* ? = (nothing, just remove)
* * = ¤ (ALT+0164)
* " = '' (two single quotes)
* < = [ or (
* > = ] or )
|
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|