Saturday 25 January 2020

windows - Displaying file names with a certain number of characters in command line


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

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...