I just tried to rename a text file with the name 1/19/2022.txt. While trying to do the same, windows is not allowing to use '/' symbol. I tried to google up the same, but couldn't find any relevant answers. I am also attaching an image to support the same. Thanks in advance.
CodePudding user response:
All the geeks will tell you to name it 20220119 - because then it'll sort nicely.
That's a remarkably short list of reserved characters.
You can't use those characters because they have special meanings and special uses, mostly to do with folder and file paths.
For example, there are lots of important files in C:\Windows\System32
Here you can see:
\
is the folder separator between one folder (Windows
) and a subfolder (System32
) this comes from DOS days.
:
is used in disk drive names. Your main drive is probably C:
. If you've got a floppy disk drive, it'll likely be A:
(but that's pretty rare). If you've got a CD or DVD ddrive that'l probably have a letter (D:
or E:
usually). If you plug in a USB drive, that used to get a letter too, but it's been a long time since I've done that, I don't know.
/
is the unix and Linux equivalent of \
- the latest versions of Windows let you use that in your path - /Windows/System32
will work too.
*
and ?
are what's known as wild-cards. *
means "any number of any character" and ?
means "one of any character". So 202201*
would find all of the files from January 2022.
The double quotes are used when you want to specify a filename that includes some other special character, for example a space (for simplicity think "anything other than a letter, a number or a full stop").
A file or folder with no spaces in it, you don't need quotes.
You could just say C:\Windows\System32\
But if you've got a space in the file or folder name then you need to indicate to Windows when the filename stops and "something else" starts, such as an option, or the next file name. So Windows uses double quotes, e.g. to reference the folder C:\Program files\
you'll need double quotes around it: "C:\Program files"
.
Similar with other special characters, such as single quotes, brackets and commas.
The three symbols <
>
and |
are redirection symbols in the Command Shell, and Windows still wants to support those.
<
is input redirection. It tells the command shell to take input from the file on the right hand side of the <
instead of from the keyboard. (That's pretty rare in my experience).
>
is output redirection - it tells the command shell to write the output of the command to a specific file. You can use two of them to append >>
- that appends to the file you specify, just one will overwrite it.
The pipe symbol |
takes the output of the command on the left, and makes it the input of the command on the right.
So you could go
dir | sort > filesSorted.txt
The first command dir
gives you a directory listing.
The pipe symbol says "take the output of the dir
command and make it the input of the sort
command"
sort
- sorts the input and writes to the output.
The >
says take the output of sort
and write it to a file named FilesSorted.txt
So if you do that command, you'd get a list of the files in the current folder sorted. And if you've named them in ISO format as I've suggested it'll be all nice. (except that dir
has some extra lines like total number of files, that'll get sorted to the top and the bottom of the file, but whatever).
As I said above, that's a remarkably short list of characters you can't use. I'd be inclined to stay away from the majority of punctuation, except for underscores.