I need to list all text files on the C drive whose names are seven characters long. I tried the following command
DIR ???????.txt
However, this command displayed files with seven characters and less. Which command could I use to only display files with seven characters?
Answer
The wildcard ?
matches any character at most once, so dir ???????.txt
will match any .txt-file with an extension preceded by at most seven characters. There is no wildcard that matches any character exactly once that dir
directly supports, but the command's output can be piped into findstr
, which supports regular expressions.
In this case, dir /B | findstr /R "^.......\.txt"
will do the trick.
No comments:
Post a Comment