Batch File Question

J

jkposey

This is hopefully a simple question. I apologize if it is placed in
the wrong group, it was difficult to find the proper group. I have
the need to create a batch file that creates a new text file. The
text file should contain one line that is the current date.

I cannot find any information on a command to create a file. Please
help!
 
R

Robert Morley

There's no command (that I remember, anyway) that simply "creates" a file in
the sense I think you mean. What you can do, however, is have the output of
a program sent to a file, which will be created if it doesn't exist, or
overwritten if it does.

Try:

date /T > myfile.txt



Rob
 
M

Martmcd

date /t >filename.txt

will create a file in the current directory with the date on one line. It
will overwrite any existing file of the same name.

hope that helps,
Martin
 
B

Bob I

creates/overwrites the named file
Robert said:
There's no command (that I remember, anyway) that simply "creates" a file in
the sense I think you mean. What you can do, however, is have the output of
a program sent to a file, which will be created if it doesn't exist, or
overwritten if it does.

Try:

date /T > myfile.txt



Rob
 
R

Robert Morley

It's a question of semantics. The create and append methods both require
existing commands to work from; they're not about creating files in their
own right. What I'm getting at is that it's not like most programming
languages where you use one command to open or create a file, then use other
commands to send information to it, then use another command to close it.

(And obviously I new about redirection, since that's what I used in my
example!)



Rob

 
B

Bob I

True, a "command" to create the file is not needed, merely passing the
filename desired to the previous command creates the file.
 
R

Robert Morley

That was how I interpreted the OP's post, which is why I worded my response
the way I did. Anyway, no harm done, and your response made it clear how it
was that the file was being created, which I failed to do, so there you go.
:)


Rob
 
B

Bob I

Have a good one!

Robert said:
That was how I interpreted the OP's post, which is why I worded my response
the way I did. Anyway, no harm done, and your response made it clear how it
was that the file was being created, which I failed to do, so there you go.
:)


Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top