1.

Solve : How to append time stamp to filename using DOS com?

Answer»

I want to WRITE a batch file which will generate the outputfiles but the filenames should be appended with TIMESTAMP at the time of run.This may work:

@echo off
for /f "tokens=1-3 delims=:. " %%i in ("%TIME%") do (
put your code here using %%i as hour, %%j as minute, %%k as second
)

Good luck. I have a java program. I run that using the batch file.
For the java program I pass the outputfile name as an argument. I want that output file name to be appended with time stamp at the time of run.

Suppose

my batchfile would contain something like this.

SET OUTPUTFILE myfile.....
java myprogram %OUTPUTFILE%


What I want here is the OUTPUTFILE should look like myfile_20050325_0150 if I run the batch file at 1 past 50 minutes of march 25th.

How to do that?If you are already outputting the file name in Java, why don't you finish the job there and append the date time stamp in java.

Why use 2 things to do what one will do? Unless there is more to the story.I cant modify the java code since I have only the executableOkay...

@echo off
for /f "tokens=2-4 delims=/ " %%x in ("%DATE%") do (
for /f "tokens=1-3 delims=:. " %%i in ("%TIME%") do set OUTPUTFILE = myfile^_%%Z%%x%%y%%i%%j
)

java javapgm %outputfile%

That should work.

Note: All these variables are dependent on the local settings for date/time format.thanks. Its working. that is great.

I was wondering if I could trouble you with one more question.


I need to find whether there is any DIFFERENCE (in the contents) between those generated outputfiles against the first one generated.

How could I do that?I'm pretty sure there is a COMP command:

COMP filename1 filename2

There also switches you can use. Type comp /? or help comp for details.

Good luck. thanks. it works



Discussion

No Comment Found