rename file with counter

Microsoft Windows server 2003 enterprise
February 11, 2010 at 04:48:20
Specs: Windows Server 2003

I am trying to achive a functionality using a batch file.

There is program which opens report and refreshes it against the database.If I again open the program to open the same report it does'nt work saying file already in use since the first execution is still goin on. So I thought of creating a copy of the original report > rename it > refresh it > delete the copy. Also it is necessary to rename the copy with a increment counter like reportcopy1.rep,reportcopy2.rep and so on. So far I could only write the below:

copy D:\TestReport.rep D:\Temp\TestReport.rep
if exist D:\Temp\TestReport.rep ren D:\Temp\TestReport.rep D:\Temp\TestReport1.rep

now how do i rename all the subsequent copies that will be created in the Temp folder with an increment in the filename.

for e.g: TestReport1.rep, TestReport2.rep , TestReport3.rep ......

I assume this could be achieved by creating a variable but not sure what the commad is.

Also, when opening the file how will i mention the file name with the variable

here is something it should look like:

copy D:\TestReport.rep D:\Temp\TestReport.rep
if exist D:\Temp\TestReport.rep ren D:\Temp\TestReport.rep D:\Temp\TestReport(VARIABLE).rep
Start "" "D:\Business Objects\busobj.exe" -document "D:\Temp\TestReport(VARIABLE).rep"
del "D:\Temp\TestReport(VARIABLE).rep"

Any directions or assitance will be highly appreacited. If this could be achieved, work will be a lot easier than manually refershing the reports.


See More: rename file with counter

Report •

February 11, 2010 at 08:47:58
set counter=0
copy D:\TestReport.rep D:\Temp\TestReport%counter%.rep
Start "" "D:\Business Objects\busobj.exe" -document "D:\Temp\TestReport%counter%.rep"
del "D:\Temp\TestReport%counter%.rep"
set counter+=1
goto :aa

but i think the whole idea might be flawed... you wind up running a million sessions simultaneously on the same file:
while test1 is being processed, you generate test2 and start processing, then you generate test3 and start processing...
it seems like the best thing would be to have the batchfile wait until the primary file is not in use by the batchfile, then make a new copy. in that case no counter is needed, just use the same name every time. various commands can be used to test read-access accessibility, maybe like:

copy D:\TestReport.rep D:\Temp\Test.rep
for /f %%a in (test.rep) do (
set xx=%errorlevel%
goto :aa
if %xx% equ 0 (
Start "" "D:\Business Objects\busobj.exe" -document "D:\Temp\Test.rep"
goto :testagin

other commands can also be used to test accessibility:
rename, fc...
same idea just test the errorlevel to see if zero.

Report •
Related Solutions

Ask Question