Muriel

Problem matching case when copying from a list

7 posts in this topic

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:

  1. in the results text file the first letter of the month is not capitalized 
  2. 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

Share this post


Link to post
Share on other sites



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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now