Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to create file with 0 bytes (length) ?

96 views
Skip to first unread message

Dennis Halver

unread,
Jul 6, 2009, 5:41:09 PM7/6/09
to
How can I create a file with 0 byte length?

Dennis

Benjamin David Lunt

unread,
Jul 6, 2009, 8:56:24 PM7/6/09
to

"Dennis Halver" <ha...@persrec.com> wrote in message
news:4a526f74$0$32682$9b4e...@newsspool2.arcor-online.net...

> How can I create a file with 0 byte length?
>
> Dennis

Using what? Since this is a MSDOS group, though I noticed
that you are coming from a NT Batch group, you can create
a zero length file many ways.

It has been a while, but if you uses DOS's Create_File
service call, then write zero bytes (CX = 0) to it,
then close is, won't that create a zero byte file?

IIRC, you *have* to call the Write_File service call
or DOS won't create the file entry. Just calling
the Create_File/Close_File service calls won't do it.

However, it have been a while so I may be wrong.

Ben

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Forever Young Software
http://www.frontiernet.net/~fys/index.htm
http://www.frontiernet.net/~fys/collections.htm
To reply by email, please remove the zzzzzz's

Batteries not included, some assembly required.


pe...@nospam.demon.co.uk

unread,
Jul 7, 2009, 12:50:52 AM7/7/09
to
In article <u2x4m.15016$Kn1....@newsfe09.iad> zf...@frontiernet.net writes:

> "Dennis Halver" <ha...@persrec.com> wrote in message
> news:4a526f74$0$32682$9b4e...@newsspool2.arcor-online.net...
> > How can I create a file with 0 byte length?
> >
> > Dennis
>
> Using what? Since this is a MSDOS group, though I noticed
> that you are coming from a NT Batch group, you can create
> a zero length file many ways.
>
> It has been a while, but if you uses DOS's Create_File
> service call, then write zero bytes (CX = 0) to it,
> then close is, won't that create a zero byte file?
>
> IIRC, you *have* to call the Write_File service call
> or DOS won't create the file entry. Just calling
> the Create_File/Close_File service calls won't do it.
>
> However, it have been a while so I may be wrong.
>
> Ben

I think it's not necessary, Ben -- at least it isn't here in
MSDOS 6.22. Maybe what you are recalling is the way to truncate
an existing file to zero bytes? In that case, you just seek to
the point in the file you want to make EOF (or in this case, the
beginning) and write zero bytes.

That said, I spent a few minutes playing around at the DOS prompt
and all that seems necessary is to run some command that writes
nothing to STDOUT and redirect to a file. For example:

echo. > tempfile.$$$
del tempfile.$$$ > zerosize.fil

creates a zero length file.

Dennis, why do you want a zero length file? Would a directory
entry suffice? Or even a volume label if you only need one such
and don't mind it being in the root dir.

Pete
--
"We have not inherited the earth from our ancestors,
we have borrowed it from our descendants."

Ted Davis

unread,
Jul 7, 2009, 9:35:16 AM7/7/09
to

They are used as flags in batch files. There are a few other, rarely
encountered, uses as well. Mostly they are used by batch files to indicate
that some process (usually the batch file itself) is running and
additional instances should self abort. They are also used to signal when
a file is in use - sort of like a write lock - to prevent or allow other
batch files to use the file or wait until it's free.

--
T.E.D. (tda...@mst.edu)

ras...@highfiber.com

unread,
Jul 7, 2009, 2:24:24 PM7/7/09
to
On Jul 6, 10:50 pm, p...@nospam.demon.co.uk wrote:

> That said, I spent a few minutes playing around at the DOS prompt
> and all that seems necessary is to run some command that writes
> nothing to STDOUT and redirect to a file.  For example:
>
>   echo. > tempfile.$$$
>   del tempfile.$$$ > zerosize.fil
>
> creates a zero length file.

rem > tempfile.$$$

is one easy way; REM doesn't display anything to stdout. Even easier,
using 4DOS, is

> tempfile.$$$

i.e. redirect output without executing any command!

--
Charles Dye

Ted Davis

unread,
Jul 7, 2009, 8:09:18 PM7/7/09
to
On Tue, 07 Jul 2009 11:24:24 -0700, raster wrote:

> rem > tempfile.$$$

That doesn't work in XP. I've never seen anyone actually use it, though
it might work in Real DOS.

A few years ago, I experimented with all the usual methods and found that
only one works in all the MS OSs:

type nul > file


--

T.E.D. (tda...@mst.edu)

ras...@highfiber.com

unread,
Jul 8, 2009, 10:08:53 AM7/8/09
to
On Jul 7, 6:09 pm, Ted Davis <tda...@mst.edu> wrote:
> On Tue, 07 Jul 2009 11:24:24 -0700, raster wrote:
> > rem > tempfile.$$$
>
> That doesn't work in XP.  I've never seen anyone actually use it, though
> it might work in Real DOS.

It does. (I'm reading this in an MS-DOS group....)

> A few years ago, I experimented with all the usual methods and found that
> only one works in all the MS OSs:
>
>   type nul > file

Very nice. That also works in 4DOS, Take Command, and the DR-DOS /
OpenDOS implementation of COMMAND.COM. I suppose the NUL device must
always return EOF on read.

--
Charles Dye ras...@highfiber.com

Jaelani

unread,
Jul 8, 2009, 11:20:05 AM7/8/09
to
ras...@highfiber.com wrote:
> On Jul 7, 6:09 pm, Ted Davis <tda...@mst.edu> wrote:
>> On Tue, 07 Jul 2009 11:24:24 -0700, raster wrote:
>>> rem > tempfile.$$$
>> That doesn't work in XP. I've never seen anyone actually use it, though
>> it might work in Real DOS.
>
> It does. (I'm reading this in an MS-DOS group....)

Odd... I should work.
But mine (XP SP3 CMD.EXE & COMMAND.COM) also don't work.

goto nowhere > file

works though.

ras...@highfiber.com

unread,
Jul 8, 2009, 12:33:43 PM7/8/09
to

XP SP3 isn't MS-DOS.

--
Charles Dye

Zaphod Beeblebrox

unread,
Jul 8, 2009, 1:59:31 PM7/8/09
to

"T Lavedas" <tglb...@cox.net> wrote in message
news:1cf74c95-922f-45b6...@t21g2000yqi.googlegroups.com...
>
> It appears the OP multi-posted and this same topic is covered in
> great
> detail over in alt.msdos.batch.nt,
>
Actually, he (yet again) crossposted and silently set followups to
AMBNT, and somewhere along the line the followup group got broken /
ignoted so that (yet again) the conversation got fragmented among the
various groups.

OP, if you are out there and reading this message, please do us the
courtesy of allowing the multipost to do what it was intended to do,
or at the very least indicate in the original post that you've set
followups to a specific group.

--
Zaphod

No matter where you go, there you are!


Ted Davis

unread,
Jul 8, 2009, 8:11:16 PM7/8/09
to
On Wed, 08 Jul 2009 07:08:53 -0700, raster wrote:

> I suppose the NUL device must
> always return EOF on read.

It does ... more or less.

--

T.E.D. (tda...@mst.edu)

Ted Davis

unread,
Jul 8, 2009, 8:13:49 PM7/8/09
to
On Wed, 08 Jul 2009 09:33:43 -0700, raster wrote:

> XP SP3 isn't MS-DOS.

True, but the original message had Followup-to: set to alt.msdos.batch.nt.

--

T.E.D. (tda...@mst.edu)

Richard Bonner

unread,
Jul 9, 2009, 7:50:24 PM7/9/09
to
Jaelani (jaej...@googlemail.com) wrote:
> ras...@highfiber.com wrote:
> > On Jul 7, 6:09 pm, Ted Davis <tda...@mst.edu> wrote:

> >> On Tue, 07 Jul 2009 11:24:24 -0700, raster wrote:
> >>> rem > tempfile.$$$
> >> That doesn't work in XP. I've never seen anyone actually use it, though
> >> it might work in Real DOS.
> >
> > It does.

> Odd... It should work.


> But mine (XP SP3 CMD.EXE & COMMAND.COM) also don't work.

> goto nowhere > file

> works though.

*** In DR-DOS, so does:

GOTO > FILE

A syntax error message appears, but the zero-byte file is created.

Richard Bonner
http://www.chebucto.ca/~ak621/DOS/

0 new messages