-1

I learnt that I can use NUL> but it is working strangely. Whenever I use it, it reports "Access is denied" but the file is created.

Amit Verma
  • 8,660
  • 8
  • 35
  • 40
I_Need_Coffee
  • 59
  • 1
  • 1
  • 10

5 Answers5

7

You're getting access denied since you're trying to run the nul device (whether you redirect standard output or not is irrelevant):

c:\pax> nul
Access is denied.
c:\pax> nul >myfile.txt
Access is denied.

What you need to do to get an empty file, although there are other ways to do it, is send the output of the nul device to your file, with something like:

c:\pax> type nul >myfile.txt

c:\pax> dir myfile.txt
 Volume in drive C has no label.
 Volume Serial Number is DEAD-BEEF

 Directory of c:\pax

21/06/2018  04:57 PM                 0 myfile.txt
               1 File(s)              0 bytes
               0 Dir(s)  31,415,926,535,902,718,281,828,459 bytes free

Only that first line above is needed to create an empty file, the rest is just to show that it worked.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
4

Just run:

echo.>your_file.txt
Roee Gavirel
  • 18,955
  • 12
  • 67
  • 94
0
mkdir thisisafile
cd thisisafile
echo.>suchtextmuchwow.txt
echo . >thisisatext.txt
notepad anothertext.txt
copy nul "iambored.txt"
type NUL > 1.txt

Note : using the " notepad " command will give you an error saying " you don't have such a file, do you want to create it? " while the "echo.>" command will directly create.

Note : if you type "echo.>" it'll create a txt file with a single line break but no characters inside, but if you type "echo . >" it'll create a text file with a dot ( . )in it.

Note : If you use "copy nul" the problem with that command is that it will always display that the file was copied and in order to avoid that you can also try the following command: type NUL > 1.txt

  • 1
    1. `echo.>...` does not create an empty file, it creates one with a single line-break! see also [this thread](https://stackoverflow.com/q/210201); 2. don't use `echo.` to create an empty line, use `echo/` or `echo(` instead! see also [this thread](https://stackoverflow.com/q/20691060); – aschipfl Jun 21 '18 at 11:43
0
copy con abc.txt

and type file content. Use Ctrl+Z to finish

Bui Dinh Ngoc
  • 447
  • 4
  • 10
0

you need to try this one it will create new file

echo.>filename

example

echo.>new.txt
Pawan Deore
  • 162
  • 3
  • 10