Computing.Net > Forums > Windows XP > Need to create a batch file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Need to create a batch file

Reply to Message Icon

Name: gjbedi
Date: October 27, 2009 at 13:32:10 Pacific
OS: Windows XP
Product: Microsoft Windows xp professional edition
Subcategory: Software Problems
Tags: Prog
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: ace_omega
Date: October 27, 2009 at 15:16:38 Pacific
Reply:

@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


-1

Response Number 2
Name: Mechanix2Go
Date: October 28, 2009 at 04:55:58 Pacific
Reply:

There's no point in guessing at the date & time layout.

Also, no colons in filename.


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

M2


0

Response Number 3
Name: gjbedi
Date: October 28, 2009 at 06:52:50 Pacific
Reply:

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


0

Response Number 4
Name: Mechanix2Go
Date: October 28, 2009 at 07:10:46 Pacific
Reply:

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


0

Response Number 5
Name: gjbedi
Date: October 28, 2009 at 07:55:11 Pacific
Reply:

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


0

Related Posts

See More



Response Number 6
Name: ace_omega
Date: October 28, 2009 at 08:19:50 Pacific
Reply:

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


0

Response Number 7
Name: ace_omega
Date: October 28, 2009 at 08:28:51 Pacific
Reply:

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"


1

Response Number 8
Name: gjbedi
Date: October 28, 2009 at 08:41:01 Pacific
Reply:

Hy Hy...

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


0

Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Need to create a batch file

Need help creating a batch file www.computing.net/answers/windows-xp/need-help-creating-a-batch-file/172372.html

How to creat a batch file www.computing.net/answers/windows-xp/how-to-creat-a-batch-file/180778.html

Help to Create a Batch File www.computing.net/answers/windows-xp/help-to-create-a-batch-file/172161.html