routama Posted May 25, 2012 Share Posted May 25, 2012 Hello, 1. In my script I use copy to clipboard -> Send("^c"). I use $name = ClipGet(). -> this string might contain one bad character or several (spaces, /, \, :, >, <, etc.) 2. and then I need to use this $name in a file name (e.g. Excel) 3. For one bad character there is no problem: If StringIsAlNum($name) = 0 Then If StringInStr($name, "/") = 0 Then Sleep(100) Else Send("c:\temp\" & StringReplace($name, "/", "_")) 4. BUT when I have a clipboard copy with sevaral bad characters, I do not know how to proceed? I could use some help. I am a total amateur, so please be simple! Thanks all! Link to comment Share on other sites More sharing options...
water Posted May 25, 2012 Share Posted May 25, 2012 (edited) To get a valid filename by replacing all invalid characters with an "_" I use the following code: ; Replace invalid characters from filename with underscore $sOL_FName = StringRegExpReplace($sOL_FName, '[ /:*?"<>|]', '_')To completely remove all invalid characters replace "_" with "". Edited May 26, 2012 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
hannes08 Posted May 25, 2012 Share Posted May 25, 2012 (edited) You can use StringReplace() to replace a single character. Edit: Well, too late Edited May 25, 2012 by hannes08 Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
routama Posted May 28, 2012 Author Share Posted May 28, 2012 Thank you so far! This is an example script I have: -> it open notepad, and copies the text (file name) from there. It contains sevaral bad characters. Then it opens Excel, and tries to save it to c:\temp\ as "copied file name". What is wrong with this? MouseClick("Left", 937, 440, 2) Sleep(1000) Send("^a") Sleep(1000) Send("^c") Sleep(1000) $name = ClipGet() MouseClick("Left", 937, 530, 2) Sleep(2000) Send("^s") Sleep(1000) If StringIsAlNum($name) = 0 Then $sOL_FName = StringRegExpReplace($sOL_FName, '[ \/:*?"<>|]', '_MOD_') Else Send("c:\temp\" & $name) EndIf Sleep(3000) Send ("{ENTER}") Sleep(3000) Link to comment Share on other sites More sharing options...
water Posted May 28, 2012 Share Posted May 28, 2012 I wouldn't automate Excel using Send commands. Use the Excel UDF that comes with AutoIt and pass the filename to function _ExcelBookSaveAs. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
routama Posted May 28, 2012 Author Share Posted May 28, 2012 I need to do it like described originally.This previous instruction sounds perfect, but I do not know how to use it.; Replace invalid characters from filename with underscore$sOL_FName = StringRegExpReplace($sOL_FName, '[ /:*?"<>|]', '_') Link to comment Share on other sites More sharing options...
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