Computing.Net > Forums > Programming > Batch file help

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.

Batch file help

Reply to Message Icon

Name: DeeJay
Date: November 30, 2004 at 05:11:56 Pacific
OS: Windows XP Professional
CPU/Ram: P4 512MB RAM, 2.6GHz
Comment:

Hi,

I have written a batch file that will write the entire contents of drive C: to a text file. I have two problems:

1) The script is told to create a new directory with the date as the current date and then create the text file with the time as the name. The problem is that the mkdir command doesn't like the %date% or %time% variables and returns an error that the syntax is incorrect. How would I get around that?

2)Everytime the script runs on an existing file (such as file.txt), it replaces all the existing text in the document with the new data. Is there a way I can change the command to add to the text file?

My script so far is this:

@ECHO OFF
C:
cd \
cd HDD
mkdir %date%
cd \
dir /OD /S > C:\%date%\%time%.txt
exit


Thanks for your help



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: November 30, 2004 at 06:51:33 Pacific
Reply:

To append text to an existing file use the >> redirector instead of >.

About %Date% and %Time% their format is not directly suitable for the MD command, but I need you post exactly what is displayed by typing

Echo D=%Date% T=%Time%

as formats are country dependent.


0

Response Number 2
Name: Mechanix2Go
Date: November 30, 2004 at 07:11:10 Pacific
Reply:

David,

The second part is easy.

To append to an existing file, use:

[command]>>file

instead of

[command]>file

The first part is a little harder.

Probably the reason the %TIME% and %DATE% vars in directory or file names does not work as hoped is that they contain illegal characters.

Colons and slashes are no good and a few other chars should be avoided.

To quickly learn which chars to avoid, try renaming a file in explorer to something containing a colon.

So depending on how your date / time formats are set [in control panel] you may get errors.

If this is the prob, you have two choices.

Change the date format to something acceptable for file / folder naming.

Or use the 'partial string' facility of XP.

Like this:

set myDATE=%DATE:~-10%

Then use myDATE.

You can guess the rest.

HTH


M2


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Homework Question!! =) Password Help for VB 6



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch file help

batch file help www.computing.net/answers/programming/batch-file-help/13830.html

Batch File Help www.computing.net/answers/programming/batch-file-help-/11464.html

batch file help www.computing.net/answers/programming/batch-file-help/190.html