Replace files and rename the new files

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Schtürmi
Newbie
Posts: 3
Joined: Mon Dec 17, 2007 5:43 pm
Location: Switzerland

Replace files and rename the new files

Post by Schtürmi » Fri Jan 11, 2008 12:05 pm

For a long time i am looking for a tool that help’s me to facilitate a very cumbersome task. So I bought macro scheduler.

The task seems easy but I don’t find a way to automate this.

From time to time I have to replace a load of application-files with the newest version of the same file. The files to be replaced are spread all over the computer and have different names, but the names allways end with the same three letters “absâ€

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

Post by Marcus Tettmar » Fri Jan 11, 2008 1:14 pm

Can you clarify - does the filename end in abs or is the extension abs? Or both? Is the file 788.abs or 788abs.??? It is not clear from your description.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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

Post by Marcus Tettmar » Fri Jan 11, 2008 1:37 pm

Pretty sure this is what you want:

Code: Select all

//Define where the new file is stored here:
Let>new_source_file=c:\the_new_file\abs.abs

//Get list of all matching files.  Modify filespec accordingly.
Let>RP_WINDOWMODE=0
Let>RP_WAIT=1
Run>cmd.exe /c dir /b /s c:\*.abs >> %TEMP_DIR%\findresults.txt

//read results list into memory - this is a list of matching files
ReadFile>%TEMP_DIR%\findresults.txt,file_list
Separate>file_list,CRLF,file_array

//loop through file list and process each one
If>file_array_count>0
  Let>x=0
  Repeat>x
    Let>x=x+1
	Let>this_file=file_array_%x%

	//now we can do what you need to do to the file here.  If I understand you correctly all you need
	//to do is copy the new file to the same name as the old file, overwriting it in the process:
	Let>CF_OVERWRITE=1
	CopyFile>%new_source_file%,this_file

  Until>x=file_array_count
Endif

DeleteFile>%TEMP_DIR%\findresults.txt
It may need tweaking as I may not quite have understood your exact requirements, but it should get you started. You may need to change the "c:\*.abs" part to suit the filespec you are searching for. Also don't forget to modify the first line to tell the script where the new abs file is that you want to replace the found files with.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Schtürmi
Newbie
Posts: 3
Joined: Mon Dec 17, 2007 5:43 pm
Location: Switzerland

Post by Schtürmi » Fri Jan 11, 2008 1:48 pm

mtettmar wrote:Can you clarify - does the filename end in abs or is the extension abs? Or both? Is the file 788.abs or 788abs.??? It is not clear from your description.
Sorry, my english is only very basic.

The filenames end in abs and the extension is allways apr; i.e. 788abs.apr

Thank you very much for your input, much appreciated. I will give it a try.

Matthias

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

Post by Marcus Tettmar » Fri Jan 11, 2008 1:52 pm

Schtürmi wrote:
mtettmar wrote:The filenames end in abs and the extension is allways apr; i.e. 788abs.apr
So this should work for you:

Code: Select all

//Define where the new file is stored here:
Let>new_source_file=c:\the_new_file\abs.apr

//Get list of all matching files.  Modify filespec accordingly.
Let>RP_WINDOWMODE=0
Let>RP_WAIT=1
Run>cmd.exe /c dir /b /s c:\*abs.apr >> %TEMP_DIR%\findresults.txt

//read results list into memory - this is a list of matching files
ReadFile>%TEMP_DIR%\findresults.txt,file_list
Separate>file_list,CRLF,file_array

//loop through file list and process each one
If>file_array_count>0
  Let>x=0
  Repeat>x
    Let>x=x+1
	Let>this_file=file_array_%x%

	//now we can do what you need to do to the file here.  If I understand you correctly all you need
	//to do is copy the new file to the same name as the old file, overwriting it in the process:
	Let>CF_OVERWRITE=1
	CopyFile>%new_source_file%,this_file

  Until>x=file_array_count
Endif

DeleteFile>%TEMP_DIR%\findresults.txt
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Schtürmi
Newbie
Posts: 3
Joined: Mon Dec 17, 2007 5:43 pm
Location: Switzerland

Post by Schtürmi » Thu Jan 17, 2008 12:57 pm

Tettmar

Your script runs like a champ. It’s exactly what I needed.
What took me hours bevor now runs in seconds! Thank you so much.

I will now investigate more time in Macro Scheduler!

Matthias

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