Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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!

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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
share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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