0

"What is the meaning of cd. > for creating empty file in windows CMD?" In my view point CD means change directory but why i have to put .> for creating empty file in windows CMD?

C:\Users\smith\Desktop\web>cd. >index.html
lit
  • 10,936
  • 7
  • 49
  • 80
sumon
  • 137
  • 1
  • 1
  • 5
  • Related: [How to create an empty file at the command line in Windows?](https://stackoverflow.com/q/1702762) and [How to create empty text file from a batch file?](https://stackoverflow.com/q/210201) Anyway, do not use `cd.` for creating an empty file! if there is a file named `cd` (no extension) in the current directory, an error arises! even if there is no such file I recommend not using this since the file system is scanned, hence this is quite slow... – aschipfl Sep 13 '19 at 11:08

2 Answers2

3

An alternative way to create a zero (0) length file. This seems more explicit and probably more quickly understood.

COPY NUL nnn.txt

or

TYPE NUL >nnn2.txt
lit
  • 10,936
  • 7
  • 49
  • 80
1

> redirects output from the preceding operation to a file handle. Unfortunately, there's no straighforward way to output an empty string with echo in cmd, so if you use:

echo. > newfile.txt

for example, you end up with newfile.txt containing a trailing new-line.

cd. "changes" the location to, well, the current location (so effectively does nothing) and then it outputs... well, nothing! The effect being that:

cd. > newfile.txt

results in an empty text file

Mathias R. Jessen
  • 106,010
  • 8
  • 112
  • 163