Batch File Question

  • Thread starter Thread starter jkposey
  • Start date Start date
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!
 
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
 
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
 
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
 
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

 
True, a "command" to create the file is not needed, merely passing the
filename desired to the previous command creates the file.
 
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
 
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
 
Back
Top