I'm creating a batch script for a class and I've hit a roadblock.

I have to list all text files whose names are up to seven characters long on the entire C: drive - make the listing output in a wide formant - then append to Batch script file output.txt.

So far I have -->

dir c:\*txt/w/o/s/p >>c:/"My Batch Script File Assigment"/"Output"/"Batch Script File Output Data".txt

The above does everything except limit the search to files with only 1-7 characters in their name.

If anyone could point me in the right direction I would really appreciate it!


If you want to list files that are between 1-7 chars long you use the "?" (question mark). The question mark represents only one unknown character. Examples:

List all the file names starting with D and comprising five or less chars, and any ext:

C>DIR C:D????.*

To copy all files beginning with S and an ext of two chars or less:

C>COPY S*.?? A:

Delete all files that have a single char filename with a doc ext from the root:

C:\>del ?.doc

Limit a search to the 1-7 character file name...

C:\> DIR ???????.txt

dir c:???????.txt/w/o/s/p >c:/"My Batch Script File Assigment"/"Output"/"Batch Script File Output Data".txt
  • Wow that's brilliant! Thanks for that, I was tearing my hair out over that question. – Jane Sep 4 '12 at 3:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.