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.
5 Answers
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.

- 854,327
- 234
- 1,573
- 1,953
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

- 31
- 5
-
11. `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
you need to try this one it will create new file
echo.>filename
example
echo.>new.txt

- 162
- 3
- 10