Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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...

@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

There's no point in guessing at the date & time layout.
Also, no colons in filename.
=====================================
Helping others achieve escape felicityM2

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

I don't know what day has to do with time but I'll stay tuned.
What is the problem?
=====================================
Helping others achieve escape felicityM2

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

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%.txtThe 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 ....

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"

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |