Fog Creek Software
g
Discussion Board




Create files from DOS command line?

How does one go about creating new, blank files from the MS-DOS command line?

I have batch file and it needs to create several empty files, but I can't seem to find any equivalent of mkdir (md) for files. The type command looked promising, as it supposedly works like Unix cat(1), but it doesn't seem to support cat's file creation behavior. Empty > redirects don't work either.

Any help is appreciated.

.-.-.
Tuesday, December 30, 2003

Stone-age solution: create a 0-byte file and just copy it around.

There's probably a better way, but it's not worth the time to figure it out.

Alyosha`
Tuesday, December 30, 2003

Not sure if this would be batchable, but here's a quick way to do it from the command line:


C:\WINNT\system32>copy con test.txt
^Z
        1 file(s) copied.

C:\WINNT\system32>dir test*
Volume in drive C is BOOT
Volume Serial Number is 303D-1CE6

Directory of C:\WINNT\system32

12/29/2003  10:28p                  0 test.txt
              1 File(s)              0 bytes
              0 Dir(s)  10,008,756,224 bytes free

C:\WINNT\system32>

Sam Livingston-Gray
Tuesday, December 30, 2003

dir/b foobar >empty.txt

Assuming foobar doesn't exist.

Big B
Tuesday, December 30, 2003

I thought it was time for me to learn stderr redirection, so to get rid of the File not Found message, add

2>nul

to the above...

Big B
Tuesday, December 30, 2003

type foo > foo

Oren
Tuesday, December 30, 2003

try echo > filenme.ext

Sunish
Tuesday, December 30, 2003

You use the copy con method to create a single file, package that with your batch file and when you need a new file copy the file to wherever you want it.

Simon Lucy
Tuesday, December 30, 2003

copy nul filename.ext

No need to type anything at the keyboard.

Ori Berger
Tuesday, December 30, 2003

copy nul filename.ext

Tapiwa
Tuesday, December 30, 2003

Ori,

the "type" in Oren's reply is a DOS command to list the conents of a text file.

pdq
Tuesday, December 30, 2003

He meant the Ctrl-Z to terminate the file, I'm covered with embarrassment, or strawberry jam, that I forgot about redirecting NUL.

Simon Lucy
Tuesday, December 30, 2003

Install cygwin and use "touch".


<ducks> ;-)

Michael Kale
Wednesday, December 31, 2003

*  Recent Topics

*  Fog Creek Home