gero Posted November 24, 2020 Posted November 24, 2020 I have a problem that when adding the files that have some special character type # in the name they do not appear in the list I wanted these special characters to be removed when showing the name in the list can anyone help? $ lista_pastas = _StringExplode ($ lista_pastas, "#", 0) _ArraySort ($ lista_pastas, 1,1,1) $ conta_cds = UBound ($ lista_pastas) $ total_cds = $ conta_cds - 1 $ qtde_casas = StringLen ($ total_cds) If $ qtde_casas <2 Then $ qtde_casas = 2 If $ total_cds> = 1 Then selecionar_cd ($ lista_pastas [1], 1) Else MsgBox (4096, "ERRO!", "Não foram encontrados cd's no catálogo indicado!", 3) Sair EndIf
Developers Jos Posted November 24, 2020 Developers Posted November 24, 2020 (edited) Moved to the appropriate forum, as the AutoIt Example Scripts forum very clearly states: Quote Share your cool AutoIt scripts, UDFs and applications with others. Do not post general support questions here, instead use the AutoIt Help and Support forums. Expand Moderation Team ps: This was the second time, so please post in the correct support forum from here on! Edited November 24, 2020 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
water Posted November 24, 2020 Posted November 24, 2020 (edited) I use the following code to remove invalid characters from a filename with an underscore: ; Replace invalid characters from filename with underscore. When $iFlags = 1 then space won't be replaced $sFName = (BitAND($iFlags, 1) = 1) ? (StringRegExpReplace($sFName, '[\/:*?"<>|]', '_')) : (StringRegExpReplace($sFName, '[ \/:*?"<>|]', '_')) Edit (4. April 2022): As we are talking about file- and foldernames "\" should be removed as well (according to user p4sCH): ; Replace invalid characters from filename with underscore. When $iFlags = 1 then space won't be replaced $sFName = (BitAND($iFlags, 1) = 1) ? (StringRegExpReplace($sFName, '[\\\/:*?"<>|]', '_')) : (StringRegExpReplace($sFName, '[ \\\/:*?"<>|]', '_')) The "solution" above removes invalid characters but the best solution would be to have a list of valid characters and remove everything else 😉 Edited April 4, 2022 by water My UDFs and Tutorials: Reveal hidden contents UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
rudi Posted December 14, 2020 Posted December 14, 2020 Hi small section of a script to cleanup filenames: $RegExKickNonAscii = "(?i)([^a-z0-9-_])" ; all but a-z0-9-_ forbidden [...] $FileNameWithExt = StringTrimLeft($ZipArchiv, StringInStr($ZipArchiv, "\", 0, -1)) $FileExt = StringTrimLeft($FileNameWithExt, StringInStr($FileNameWithExt, ".", 0, -1)) $FileName = StringLeft($FileNameWithExt, StringInStr($FileNameWithExt, ".", 0, -1) - 1) $FileNameAsciiClean = StringRegExpReplace($FileName, $RegExKickNonAscii, "") & "." & $FileExt ; replace-with = "" means "kick" not wanted chars. [...] Earth is flat, pigs can fly, and Nuclear Power is SAFE!
jchd Posted December 14, 2020 Posted December 14, 2020 On 12/14/2020 at 12:54 PM, rudi said: $RegExKickNonAscii = "(?i)([^a-z0-9-_])" ; all but a-z0-9-_ forbidden Expand Good but won't work for people whose language use extra ASCII characters, leave alone most of Unicode. Remember most humans on Earth don't use a latin alphabet. Reveal hidden contents This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
rudi Posted December 15, 2020 Posted December 15, 2020 (edited) @jchd the OP mentioned: "...I wanted these special characters to be removed ..." isn't it? Exactly this was my task as well, for the script I took these lines from: simply kick all non ASCII chars (ftp server url conformity) For me it's the German Umlauts "äöüÄÖÜ" and the beautiful "ß" Edited December 15, 2020 by rudi Earth is flat, pigs can fly, and Nuclear Power is SAFE!
FrancescoDiMuro Posted December 15, 2020 Posted December 15, 2020 On 12/15/2020 at 12:47 PM, rudi said: and the beautiful "ß" Expand You mean sseautiful? Click here to see my signature: Reveal hidden contents ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now