Muriel Posted February 12, 2016 Share Posted February 12, 2016 I have a script that reads the files in a directory to a list, opens those in a separate program, and then saves the resulting data with the same file name (in a different directory) as a text file using notepad. The script works fine but occasionally there are some issues with writing the file names that I don't understand. All of the file names are in the format '####Mmm#(#(#(#))).txt' (number padded to 4 digits with zeros, month as three letters with the first one capitalized, number not padded with zeros. The problems that come up are: in the results text file the first letter of the month is not capitalized the first number is written as its corresponding symbol (# for 3, $ for 4, % for 5, etc). This is especially an issue, because when the number includes an 8 (*), the file cannot save. Any ideas where I've gone wrong? Thanks! $filelist = _FileListToArray( @WorkingDir ) For $iter = 1 To $filelist[0] Step 1 $curfile = $filelist[$iter] ... ;do some stuff that ends with data being copied to clipboard ... Run('notepad.exe') WinWaitActive('Untitled - Notepad') Send('^v') ;paste clipboard WinClose('Untitled - Notepad') WinWaitActive('Notepad', 'Save') Send('!S') ;press save WinWaitActive('Save As') ControlSend('Save As','','[CLASS:Edit; INSTANCE:1]','^a'&'{BACKSPACE}') ;clears text in field ControlSend('Save As','','[CLASS:Edit; INSTANCE:1]',$curfile&'{ENTER}') ;pastes file name and hits enter Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 12, 2016 Moderators Share Posted February 12, 2016 Muriel, Welcome to the AutoIt forums. "*" is not permitted in file names (it is the "any number of characters" wildcard) so it is not surprising that the file will not save. You need to rethink your substitution code. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Muriel Posted February 12, 2016 Author Share Posted February 12, 2016 Melba23: Quote "*" is not permitted in file names (it is the "any number of characters" wildcard) so it is not surprising that the file will not save. You need to rethink your substitution code. I realize that. I do not want it to substitute anything and I don't know why it is. That is my issue. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 12, 2016 Moderators Share Posted February 12, 2016 Muriel, My apologies - I misread the OP. I suggest you use something like this to correct the filename: Global $iSubst[10] = [")", "!",'"', "£", "$", "%", "^", "&", "*", "("] ; Original $sFileName = "*###mmm#(#(#(#))).txt" ConsoleWrite($sFilename & @CRLF) ; Extract first number $sFirstNumber = StringLeft($sFileName, 1) For $i = 0 To 9 If $sFirstNumber = $iSubst[$i] Then $sFilename = $i & StringTrimLeft($sFilename, 1) ConsoleWrite($sFileName & @CRLF) EndIf Next ; Make sure first letter of month is uppercase $sFileName = StringMid($sFileName, 1, 4) & StringUpper(StringMid($sFileName, 5, 1)) & StringMid($sFileName, 6) ConsoleWrite($sFileName & @CRLF) M23 Skysnake 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Skysnake Posted February 17, 2016 Share Posted February 17, 2016 I am curious, and perhaps there is some sub text I miss here, why not simply fix it with a StringReplace Regex? Skysnake Why is the snake in the sky? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 17, 2016 Moderators Share Posted February 17, 2016 Skysnake, If it is that simple, where is your suggested solution? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Skysnake Posted February 17, 2016 Share Posted February 17, 2016 I am asking, because I am not sure I understand the question. I am not criticizing the suggested answer. Perhaps the point I miss is this, is the 'symbol to digit' matching relevant? Or can one simple replace the symbols with '_'? Either way For $iter = 1 To $filelist[0] Step 1 $curfile = $filelist[$iter] ; this will simply result in replacing all symbols with underscore ; my attempt StringReplace $curfile = StringReplace($curfile,'!','_') $curfile = StringReplace($curfile,'@','_') ; repeat until all replaced ; my attempt StringReplace $curfile = StringRegExpReplace($curfile,'[!@#$%^&*()]','_') ; tested the regex here https://regex101.com/ ... ;do some stuff that ends with data being copied to clipboard) Skysnake Why is the snake in the sky? 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