Rename leaves original file

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
obfusc88
Pro Scripter
Posts: 87
Joined: Wed Mar 14, 2007 6:22 pm

Rename leaves original file

Post by obfusc88 » Thu Dec 09, 2010 12:38 am

I have tried to rename a file, but the original file still remains in the folder.
Using Macro Scheduler 11.1.20 on XPPro-SP3
Here is a simple sample......

Code: Select all

Month>mm
Day>dd
Year>yyyy
Let>Today=%yyyy%%mm%%dd%

Let>SourceFolder=N:\Data\Db
Let>FileName=EXPORTS
Let>FileExt=ASC
Let>FullFileName=%FileName%.%FileExt%

ChangeDirectory>%SourceFolder%

RenameFile>%FullFileName%,%FileName%_%Today%.%FileExt
I know I can add more lines and delete the original file if both exist, but this seems unnecessary. Gets more complex if more than one file is involved.

This looks similar to this posting: http://www.mjtnet.com/forum/viewtopic.p ... renamefile

=================
I just tried the MoveFile and that worked OK. This seems like a bug and the HELP file should make a note to use MoveFile until this is corrected.

Code: Select all

Let>MF_RENAME=1
MoveFile>%SourceFolder%\%FullFileName%,%SourceFolder%\%FileName%_%Today%.%FileExt%

sarver311
Pro Scripter
Posts: 84
Joined: Tue Jun 17, 2008 6:37 pm

Post by sarver311 » Tue Mar 08, 2011 4:12 pm

This seems to work fine in Windows 7 but the bug definitely appears under Windows XP even under MS 12.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Mar 09, 2011 1:23 pm

Odd. This command simply calls the SHFileOperation API call with the flag in the SHFILEOPTSTRUCT set to FO_RENAME. So we're really just passing the command on to the operating system to fulfil.

http://msdn.microsoft.com/en-us/library ... s.85).aspx
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts