I have already supplied this functionality. The explanation for the macro in my second post is mainly explaining how saving the new files with an auto-increasing number in the file name is done and most of the code of the macro in my second post is just for this functionality. However, if you want a stand alone macro for saving a file with an auto-increasing number, here it is.
Macro
FileNameNumber
Code: Select all
InsertMode
ColumnModeOff
Top
Clipboard 8
Paste
"|"
Find RegExp Up "[0-9]"
EndSelect
Key LEFT ARROW
OverStrikeMode
Loop 0
IfCharIs "0"
"1"
ExitLoop
EndIf
IfCharIs "1"
"2"
ExitLoop
EndIf
IfCharIs "2"
"3"
ExitLoop
EndIf
IfCharIs "3"
"4"
ExitLoop
EndIf
IfCharIs "4"
"5"
ExitLoop
EndIf
IfCharIs "5"
"6"
ExitLoop
EndIf
IfCharIs "6"
"7"
ExitLoop
EndIf
IfCharIs "7"
"8"
ExitLoop
EndIf
IfCharIs "8"
"9"
ExitLoop
EndIf
IfCharIs "9"
"0"
Key LEFT ARROW
IfColNum 1
InsertMode
"1"
ExitLoop
EndIf
Key LEFT ARROW
IfCharIs "0123456789"
Else
Key RIGHT ARROW
InsertMode
"1"
ExitLoop
EndIf
EndIf
EndLoop
InsertMode
Top
StartSelect
Find Select "|"
Key LEFT ARROW
Cut
EndSelect
Delete
This macro consists mainly of the code from macro
CountUp. Just the code at top is slightly changed and the code at bottom is simplified for the purpose of this macro.
The final file name is stored in user clipboard 8 after playing this macro with the command
PlayMacro 1 "FileNameNumber"
and therefore just the command
SaveAs "^c" must be used to save the current file with the file name with the auto-increasing number inside.
Please note that first the macro
FileNameNumber must be created before any other macro stored in the same macro file playing this macro can be created.
Further take into account that clipboard 8 is used as string variable buffer for the file name. So make sure to use another clipboard in the main macro playing macro
FileNameNumber to increase the number in the file name. In other words after saving a new file with command
SaveAs "^c" the next command before using any clipboard again in code execution sequence should be
Clipboard x with
x is 0 to 9 except 8.
Last the macro can't be used as is without an initialization of the file name in clipboard 8. It is necessary that the main macro contains code to copy a valid file name with or without path into user clipboard 8. I suggest to initialize clipboard 8 always with a file name with full path because a new file saved with a file name without path is saved in the current working directory of UE/UES which could be also the program directory of UE/UES which is often write-protected and therefore saving the files fail. Here is a code example for initializing clipboard 8 with a file name.
Top
"C:\Temp\Temp_00.txt"
SelectToTop
Clipboard 8
Cut
Clipboard 0
Of course the file name string could be also manually copied into clipboard 8 before running any macro.
Important is that the file name contains a number. If this number starts with
0 or for example with
2395 does not matter. The number of leadings zeros also does not matter. But it is advisable to use the right number of zeros in the initial file name string according to the expected number of files to not get files with the numbers 1, 2, 3, ..., 8, 9, 10, etc. but get instead files with 01, 02, 03, ..., 08, 09, 10, etc.
As an example for usage of macro
FileNameNumber let us assume that a macro is needed to create 10 files with a file name entered by the user and the content for the 10 files should be the current content of the Windows clipboard.
Code: Select all
InsertMode
ColumnModeOff
HexOff
UnixReOff
NewFile
GetString "Please insert the file name with path."
Find Up "."
IfNotFound
"_00.txt"
Else
EndSelect
Key LEFT ARROW
"_00"
Key END
EndIf
SelectToTop
Clipboard 8
Cut
CloseFile NoSave
Loop 10
Clipboard 0
NewFile
Paste
PlayMacro 1 "FileNameNumber"
SaveAs "^c"
CloseFile NoSave
EndLoop
ClearClipboard
Clipboard 0