Click to See Complete Forum and Search --> : creating a file from the command line
HighCommander4
June 14th, 2007, 04:55 PM
Is there any way to create a text (or any) file from the Windows command line? Suppose I wanted a text file located in C:\ called "file.txt" which contains the text "TEXT". I'm thinking of a command similar to this:
create C:\file.txt "TEXT"
Is there any functionality similar to this?
PeejAvery
June 14th, 2007, 05:34 PM
Try...
echo This will show up in the text file > c:\file.txt
S_M_A
June 14th, 2007, 05:55 PM
Or good old copy con C:\file.txt, enter - type the text - finish with ctrl-z & enter
PeejAvery
June 14th, 2007, 06:11 PM
I thought of that first but that requires user input. The way HighCommander4 describes it is without user input.
S_M_A
June 14th, 2007, 06:34 PM
Oh, didn't realize that! You're probably right. This is intended for a batch file I guess.
HighCommander4
June 14th, 2007, 06:53 PM
Thank you PeejAvery, your solution works. (It is indeed for a batch file.)
What if my text has a enter (linefeed) in it? I need to be able to do it in one command...
EDIT: Scratch that, I can do it in multiple commands? But how *do* you make a second echo append the text to the already existing file rather than overwriting it?
PeejAvery
June 14th, 2007, 07:24 PM
To append use >> instead of >.
HighCommander4
June 14th, 2007, 07:50 PM
Thank you once again PeejAvery! I got it to work now. :thumb:
PeejAvery
June 14th, 2007, 10:53 PM
Glad to be of help! And thanks for the rate! :wave:
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.