I wrote a batch file that examines the output of dir ???????.txt
and echoes only the files that have 7 characters (11, including .txt).
@ECHO OFF
REM --- Call Subroutine for all files of Len 1 - 7 characters ---
For /f "delims=*" %%a in ('dir "c:\???????.txt" /b') do Call :CheckLen %%~nxa
REM --- End Batchfile ---
Goto :eof
:CheckLen
REM --- Place Filename in Variable FNAME ---
Set FName=%*
REM --- IF Valiable FName <> First 10 characters of FName, FName has ---
REM --- 11 Characters (7 + .txt). Echo Output ---
if NOT "%FName%"=="%FName:~0,10%" Echo %FName%
Note: In line 'dir "c:\???????.txt" /b'
,add /s
if you want also to search the subdirectories of C:. This will probably take a long time without output.
this is exactly what i'm looking for thankyou you have been a huge help – batsta13 – 2012-03-22T12:16:50.047
So then this is wrong? http://ss64.com/nt/dir.html "
– Morpfh – 2012-03-22T13:15:33.280? Match any ONE character
", or , http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/dir.mspx?mfr=true , it say ? substitute one character, not "at most one".1As far as I know, the ?-wildcard has matched zero or one character ever since MS-DOS. Likewise, the character
?
is used in regular expressions to match the preceding element zero or one times, but after some digging, it seems there is more to it. Apperently,?
will only match zero characters when it preceeds either another wildcard, a dot or the end of a string, in Windows 7, that is. How convenient! – Marcks Thomas – 2012-03-22T13:39:15.170I love this solution. It took me a while though to figure out how I can use it with subdirectories (dir /b /s) because it also returned files like c:\test\aa.txt (yes, test\aa has 7 characters too). I found the solution in the commandline: dir /B /s| findstr /R "\[^\][^\][^\][^\][^\][^\][^\].txt$" – ZEDA-NL – 2012-03-22T14:06:47.317
@MarcksThomas Ok, thanks. Thought so, but the "documentation" I found was a bit vague/misleading. – Morpfh – 2012-03-22T14:58:24.447
maybe empty string is a character for them. but they should write it better and give 2-3 examples along with find str – tgkprog – 2013-05-04T08:33:33.253