Copy and rename files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
alienxxx
Posts: 5
Joined: 22 Nov 2012 12:45

Copy and rename files

#1 Post by alienxxx » 22 Nov 2012 12:55

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Copy and rename files

#2 Post by foxidrive » 22 Nov 2012 16:08

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?

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Copy and rename files

#3 Post by abc0502 » 22 Nov 2012 20:27

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.

alienxxx
Posts: 5
Joined: 22 Nov 2012 12:45

Re: Copy and rename files

#4 Post by alienxxx » 29 Nov 2012 14:04

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.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Copy and rename files

#5 Post by abc0502 » 29 Nov 2012 14:45

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

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Copy and rename files

#6 Post by abc0502 » 29 Nov 2012 17:13

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.bat

Code: 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

Post Reply