Hello,
I am evaluating version 11 and my problems are likely self induced...
I have a bunch of files where the names include a date section like this:
FileNameA_20091224.exe
FileNameA_20091220.exe
FileNameB_20091220.exe
I need to find the most recent version of each and move it to a new folder giving a new file name that drops the last part of the fiel name, like this:
FileNameA.exe
FileNameB.exe
Any existing file can be overwitten, since it will be older.
I tried the RenameFile command first, figuring I'd worry about dates and moving files later but rename it does not seem to work with wild cards. Perhaps I mis-used it?
RenameFile>K:\Acme\FileNameA?????????.exe, K:\Acme\FileNameA.exe
I tried debugger but it didn't display anything in the watch window except my machine info / username etc.
Bye the way, how does one clear the watch list without closing the editor?
Thanks in advance,
Bob
rename files with wild cards
Moderators: JRL, Dorian (MJT support)
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
You are correct, those wildcards will not work with Rename>
Here are two approaches for renaming that you might consider.....
1. You could use RegEx> to extract the "core" filename, everything to the left of the "_" character.
2. Instead of RegEx, you could use Position> to calculate the position of the "_" character and then use MidStr> to extract the "core" filename. You would use the Position value as the string ending point reference in MidStr>.
-----------------
I have no time to provide example now. I would probably use the RegEx command, only one line needed, very fast.
Here are two approaches for renaming that you might consider.....
1. You could use RegEx> to extract the "core" filename, everything to the left of the "_" character.
2. Instead of RegEx, you could use Position> to calculate the position of the "_" character and then use MidStr> to extract the "core" filename. You would use the Position value as the string ending point reference in MidStr>.
-----------------
I have no time to provide example now. I would probably use the RegEx command, only one line needed, very fast.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
By most recent I assume you mean the one with the most recent date in the filename, not necessarily the most recently modified file, which could be different.
I would use GetFileList to retrieve a list of matching files (e.g. FileNameA*.exe). Sort the list so you have the one with the most recent date in the filename first (or last) and then rename that one.
This example sorts a file list:
http://www.mjtnet.com/forum/viewtopic.php?t=3414
So if you change the file spec to FileNameA*.exe you'll then have the "most recent" file name at the end of the list, so you just have to rename Files_%Files_Count%:
Let>theFile=Files_%Files_Count%
RenameFile>theFile,wherever/whatever.exe
I would use GetFileList to retrieve a list of matching files (e.g. FileNameA*.exe). Sort the list so you have the one with the most recent date in the filename first (or last) and then rename that one.
This example sorts a file list:
http://www.mjtnet.com/forum/viewtopic.php?t=3414
So if you change the file spec to FileNameA*.exe you'll then have the "most recent" file name at the end of the list, so you just have to rename Files_%Files_Count%:
Let>theFile=Files_%Files_Count%
RenameFile>theFile,wherever/whatever.exe
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?