| This macro subroutine takes a desired file
name generated in the parent macro and tests to see if it exists already.
If it does already exist it appends with a number and increments until
unique. The format is NNNNN including leading zeros with a maximum number
of 100,000 file name increments. The leading zeros are so the files will
appear in order when sorted by file name. The 10,000 value was picked
because it's the fundamental limit of Macro Express's repeat command. The
entire name with path is written back to the feedback registry value where
after a variable restore the parent macro can use it for a move, rename or
whatever. This is handy when you just want to stuff something in a folder
and don't care if one already exists with that name already. With this
macro you don't need to test if the destination file already exists. You
need to write the desired file name to the feedback registry value before
calling the macro. Then read back from the feedback variable to do your
file manipulation command.
The sample file is a complete Macro express file. Simply open it with
ME and run the demo macro.
Page last updated:
02/05/2008
|
| Macro Script |
Variable Save All Variables
Clear Text Variables: All
Clear Integer Variables: All
Read Registry String: "feedback"
Variable Set From File Path
If File Exists "%T1%"
Repeat Start (Repeat 99999 times)
Variable Modify Integer: %N1% = %N1% + 100000
Variable Modify Integer: Convert %N1% to text string %T6%
Variable Modify String: Delete Part of %T6%
If Not File Exists "%T2%%T3%%T4%%T6%%T5%"
Variable Set String %T7% "%T2%%T3%%T4%%T6%%T5%"
Write Registry String: "feedback"
Repeat Exit
End If
Repeat End
End If
Variable Restore All Variables |
| Macro Text |
|
<VARSR:01><CLEARVAR1:T:ALL><CLEARVAR1:N:ALL><REGRSTR:1:HKEY_LOCAL_MACHINE\SOFTWARE\Insight
Software Solutions\Macro
Express\Miscellaneous\feedback><VFFILE:1:T:2:T:3:T:4:T:5:%T1%><IFOTH:01:2:%T1%><REP3:01:000001:000001:99999:1:01:><NMVAR:01:01:1:0000001:2:0100000><NMVAR:05:01:0:0000006:0:0000000><TMVAR2:11:06:00:001:001:><IFOTH:09:2:%T2%%T3%%T4%%T6%%T5%><TVAR2:07:01:%T2%%T3%%T4%%T6%%T5%
><REGWSTR:7:HKEY_LOCAL_MACHINE\SOFTWARE\Insight Software
Solutions\Macro Express\Miscellaneous\feedback><EXITREP><ENDIF><ENDREP><ENDIF><VARSR:05> |
Here is a sample lead in demo. This demonstrates how to get in
and out of the macro. It does not do any file manipulation. I predefine T5
as autoexec.bat as most people will already have this file but it will
allow you to choose another if you like. If you define a file that doesn't
exist the incrementer skips. You need to import the macro above first
before running this.
Demo
|
| Macro Script |
Text Box Display: Sample for file name incrementer
Variable Set String %T5% "c:\autoexec.bat"
If Message: "File name"
If Message: "File name"
Variable Set String %T5% from File Name
Else
Variable Set String %T5% from Prompt
End If
End If
Write Registry String: "feedback"
Macro Run: File name increment
Read Registry String: "feedback"
Text Box Display: Results |
| Macro Text |
|
<TBOX4:T:1:CenterCenter000278000200:000:Sample for file name
incrementerThis sample macro will demonstrate the file incrementer
subroutine.><TVAR2:05:01:c:\autoexec.bat><IFMESS3:00000:1:1:File nameI
set T5 to %T5% as most people will already have this file on their
system. Would yo ulike to define a different one?Center:Center><IFMESS3:00000:1:4:File
nameWould you like to select a file or type in a value?SelectType inCenter:Center><TVAR2:05:09:><ELSE><TVAR2:05:02:FWhat
would you like as a file name?FFCenter:Center><ENDIF><ENDIF><REGWSTR:5:HKEY_LOCAL_MACHINE\SOFTWARE\Insight
Software Solutions\Macro Express\Miscellaneous\feedback><MACRUN2:File
name increment><REGRSTR:5:HKEY_LOCAL_MACHINE\SOFTWARE\Insight Software
Solutions\Macro
Express\Miscellaneous\feedback><TBOX4:T:1:CenterCenter000278000200:000:ResultsThe
next available file name is %T5%.> |
|