Need to create a batch file

Microsoft Windows xp professional editio...
October 27, 2009 at 13:32:10
Specs: Windows XP
Hi All,

I have one scheduled batch file which runs after every 2 hours and gives the output in one file, But I want that it should give the output in diffrent file.

Like:- right now I am getting the output as "output.txt" but I want the output as output_2:00 PM_26-10-2009.txt that means the file name should contains the Time as well as Date.

Please help me out in this.

Regards,
Gaurav...


See More: Need to create a batch file

Report •


#1
October 27, 2009 at 15:16:38
@echo off

Set Month=%Date:~-4,4%-%Date:~-10,2%
Set Day=%Time:~-11,2%;%Time:~-8,2%;%Time:~-5,2%_%Date:~-4,4%-%Date:~-10,2%-%Date:~-7,2%

Echo Hello > output_%Day%.txt


Report •

#2
October 28, 2009 at 04:55:58
There's no point in guessing at the date & time layout.

Also, no colons in filename.


=====================================
Helping others achieve escape felicity

M2


Report •

#3
October 28, 2009 at 06:52:50
Hi Ace Omega,

The codes which you have provide is not working as it should.

Please find codes which you have given and I added my Ping request and so on like that I need to create the script.

___________________________________
@echo off
Ping 192.168.1.1 >>output.txt

Set Month=%Date:~-4,4%-%Date:~-10,2%
Set Day=%Time:~-11,2%:%Time:~-8,2%:%Time:~-5,2%_%Date:~-4,4%-%Date:~-10,2%-%Date:~-7,2%

Echo Hello > output_%Day%.txt
___________________________________

Please help me out in this....

Regards,
Gaurav Bedi


Report •

Related Solutions

#4
October 28, 2009 at 07:10:46
I don't know what day has to do with time but I'll stay tuned.

What is the problem?


=====================================
Helping others achieve escape felicity

M2


Report •

#5
October 28, 2009 at 07:55:11
Thanks Mechanix2Go,

Actully I have one scheduled batch file which runs after every 2 hours and gives the output in one file, But I want that it should give the output in diffrent file each time it runs.

Like:- right now I am getting the output as "output.txt" but I want the output as "output_2:00 PM_26-10-2009.txt" that means the file name should contains the Time as well as Date.

Please help me out in this.

Regards,
Gaurav...


Report •

#6
October 28, 2009 at 08:19:50
Sorry I wrote it off the top of my head and I forgot you can't use ":" in files names. Here I replaced the ":" with "."....

@echo off
Set Day=%Time:~-11,2%.%Time:~-8,2%.%Time:~-5,2%_%Date:~-4,4%-%Date:~-10,2%-%Date:~-7,2%
Ping Yahoo.com > Output_%day%.txt

The problem is that you can't use spaces in DOS scripting so this only works with Post Meridian times. So I used GOOGLE which every one should do and found this....

Set CURRDATE=%TEMP%\CURRDATE.TMP
DATE /T > %CURRDATE%
Set PARSEARG="eol=; tokens=1,2,3* delims=/, "
For /F %PARSEARG% %%i in (%CURRDATE%) Do Set MMDDYY=%%j%%k%%l
ping google.com >>"PING%MMDDYY%.txt"

This was at ....

http://www.experts-exchange.com/OS/...


Report •

#7
October 28, 2009 at 08:28:51
I got it I just needed quotes so that it would except the space. *Slaps Forehead* Some times I am such an idiot.

@echo off
Set Day=%Time:~-11,2%.%Time:~-8,2%.%Time:~-5,2%_%Date:~-4,4%-%Date:~-10,2%-%Date:~-7,2%
Ping Yahoo.com > "Output_%day%.txt"


Report •

#8
October 28, 2009 at 08:41:01
Hy Hy...

Thanks Ace Omega.....it worked.....thanks a ton....


Report •


Ask Question