Page 1 of 1
Copy and rename files
Posted: 22 Nov 2012 12:55
by alienxxx
Hi.
I have a program running that is giving me output in every 5 min. the output file is having the same name ( suppose A.hsf,).
I need a batch program that copies the file from first simulation as A1.hsf and for next simulation it will again copy and rename A.hsf as A2.hsf. Please help in this matter. Thank you.
Re: Copy and rename files
Posted: 22 Nov 2012 16:08
by foxidrive
How do you know that the program has finished and the output file is ready for copying?
Does the program run in a batch file?
Re: Copy and rename files
Posted: 22 Nov 2012 20:27
by abc0502
As Foxidrive said, if we don't know when the batch will finish the file it will be difficult.
If you could post the code here we can help you to modify the out put name when the files is created so it rename the files in sequence, we did something like that before on zip files.
Re: Copy and rename files
Posted: 29 Nov 2012 14:04
by alienxxx
Sorry for such late reply guys. I was caught sick and now returning from hospital.
coming to topic , yes am using a batch file and the delay is about 5 seconds between two succesive iterations. Thanks.
Re: Copy and rename files
Posted: 29 Nov 2012 14:45
by abc0502
where it will copy the new renamed files?
And if it's ok to post your batch here, we can modify the way the file names are being created to they will be created with a sequential names and then copy them to the location you want
Re: Copy and rename files
Posted: 29 Nov 2012 17:13
by abc0502
Hi, Here is a batch file that will rename every file that being created by your batch after a small delay to make sure the file is no longer used by the your batch.
This Batch depends on that you know the name of the .hsf file that is being created.
& you know how long your batch take to create every .hsf file.
At First,
> You will have to modify your batch by adding this line at the second line in you batch:
Code: Select all
Start "Renaming" CMD.EXE /C "rename.bat"
Then Modify this Variables "
default_hsf_name" , "
Main_Time" & "
Delay_time" in the rename.bat file.
default_hsf_name : is the default name without extension your batch create.
Main_Time : is the time your batch take to create the .hsf file.
Delay_Time : is the time your batch take to create the .hsf file + 25% of that time.
Then each time you start your batch the rename.bat will start with it and after your batch finish a .hsf file and after the delay it will rename it by adding a sequential number after it's name.
This Assume There is no Previous run or already existing .hsf files, the folder that contain your batch and the rename.bat must be empty.
rename.batCode: Select all
@echo off
Title Renaming Files
Mode 15,5
:: Default name of the first hsf file
Set "default_hsf_name=AAA"
Set "Main_Time=10"
Set "Delay_Time=12
:: Time is decided by adding the time the main batch take to create the
:: hsf file and added 25% of that time on that so : Time = hsf_time + ( hsf_time * 25%)
Ping localhost -n %Delay_Time% >nul
:: First Run When there is ONLY the FIRST hsf file in the Current Folder
Set "num=1"
IF not exist "%default_hsf_name%%num%.hsf" (
Ren "%default_hsf_name%.hsf" "%default_hsf_name%%num%.hsf"
) Else (
:loop
:: This Time is set equal to the time the main batch will take create one hsf file
Ping localhost -n %Main_time% >nul
set /a num += 1
Setlocal EnableDelayedExpansion
Ren "%default_hsf_name%.hsf" "%default_hsf_name%!num!.hsf"
Endlocal
Goto :loop