DOS and filename pattern matching

  Tj_El 19:18 23 Nov 04
Locked

Hi, hope to find an answer here..

Been trying to get the "DIR" command in DOS to return a list of files matching a pattern like you get when done in Windows Explorer.

All my text files start with 3 characters (alpha) e.g. ABC, followed by the constant 3 characters again alpha eg. KKK, then followed by a string of alpha-numeric characters. What I want to do is list only those files where there are up to 4 digits after the constants e.g. ABCKKK123.txt, BCDKKK223.txt, and FGHKKK2564.txt.

Doing this in Windows Explorer using the pattern ???KKK???.txt works fine but in DOS, it simply lists all files that match the pattern ???KKK and ignores everything else so I get the full directory list - not the desired result.

Any suggestions?

Many thanks! :-)

  Tj_El 13:03 25 Nov 04

^ bump ^

  Sethhaniel 13:32 25 Nov 04

five letters + 3 extension long or something small like that
may have to look into that ??

  Sethhaniel 13:35 25 Nov 04

DOS Lesson 7. DOS Filenames; ASCII. DOS Filenames. DOS filenames follow what is called the 8.3 convention. This means that all DOS filenames have two parts, with up to 8 and 3 characters respectively.

so have to drop one of your '?'s off maybe ;)

  Tj_El 13:47 25 Nov 04

Thanks Sethhaniel. Can't change the filenames unfortunately (work-related you see..)

Would you know if there be a way around this restriction so I can still accomplish the required?

Thanks for any help you can give.

With regards,

Tj_El

  Sethhaniel 14:07 25 Nov 04

The asterisk (*) wildcard character cannot be placed before a static string in a wildcard search path. When the MS-DOS file search routines find an asterisk wildcard character in a path, the routines fill the remaining filename field with the question-mark (?) wildcard character. When this happens, any static text in the filename following the asterisk is discarded.
MORE INFORMATION
For example, the following wildcard string:
FIL*NAM.*

is interpreted by MS-DOS as follows:
FIL?????.???

This string finds all files starting with the character string "FIL" instead of all files beginning with "FIL" and ending with "NAM" and having a non-specific number and type of characters between "FIL" and "NAM." To find the files as described above, three separate searches must be made. These searches are as follows:
FILNAM.*
FIL?NAM.*
FIL??NAM.*

  Tj_El 14:18 25 Nov 04

From what you've stated above I cannot use wildcards because it would follow the routine "*INV*.txt" which would result in the return of all the files in that directory that contain those 3 letters "INV" quite a few of which are not required in the search result :-(

Incidentally where are you getting your information from? A book?

  Sethhaniel 14:36 25 Nov 04

click here
is a DOS index of commands ;)

  Tj_El 14:43 25 Nov 04

The first is using the asterisk as the wild-card and this gives all files meeting the specification. The next is using the question mark to signify single characters before and after the constant string "INV" and this does not even return the full expected list, bringing through some files but leaving others of same name format!!!

C:\>cd tel\desktop\expfiles

C:\TEL\desktop\ExpFiles>dir *INV*.txt
Volume in drive C has no label.
Volume Serial Number is 002A-2A4D

Directory of C:\TEL\desktop\ExpFiles

04/11/2004 05:15 302,934 DirectINV_04112004.txt

05/11/2004 05:15 295,766 DirectINV_05112004.txt

06/11/2004 05:15 341,910 DirectINV_06112004.txt

07/11/2004 05:15 344,150 DirectINV_07112004.txt

08/11/2004 05:15 358,934 DirectINV_08112004.txt

04/11/2004 04:00 1,599 EURINV 241_Audit.txt

06/11/2004 04:00 1,299 EURINV 246_Audit.txt

07/11/2004 04:00 1,299 EURINV 249_Audit.txt

08/11/2004 04:00 1,599 EURINV 251_Audit.txt

04/11/2004 04:00 639 EURINV241.txt

06/11/2004 04:00 368 EURINV246.txt

07/11/2004 04:00 368 EURINV249.txt

08/11/2004 04:00 639 EURINV251.txt

04/11/2004 04:00 62,499 GBPINV 239_Audit.txt

05/11/2004 04:00 64,898 GBPINV 242_Audit.txt

06/11/2004 04:00 40,897 GBPINV 243_Audit.txt

07/11/2004 04:00 85,596 GBPINV 247_Audit.txt

14/11/2004 04:00 105,398 GBPINV 260_Audit.txt

04/11/2004 04:00 44,342 GBPINV239.txt

05/11/2004 04:00 50,952 GBPINV242.txt

06/11/2004 04:00 33,312 GBPINV243.txt

07/11/2004 04:00 56,824 GBPINV247.txt

08/11/2004 04:00 35,719 GBPINV250.txt

06/11/2004 04:00 1,299 JPYINV 244_Audit.txt

06/11/2004 04:00 368 JPYINV244.txt

04/11/2004 05:25 6,294,608 UnPostedINV_04112004.txt

05/11/2004 05:25 6,257,386 UnPostedINV_05112004.txt

06/11/2004 05:25 6,314,225 UnPostedINV_06112004.txt

07/11/2004 05:25 6,337,866 UnPostedINV_07112004.txt

08/11/2004 05:26 6,348,429 UnPostedINV_08112004.txt

09/11/2004 05:26 6,963,598 UnPostedINV_09112004.txt

04/11/2004 04:00 1,299 USDINV 240_Audit.txt

06/11/2004 04:00 2,199 USDINV 245_Audit.txt

07/11/2004 04:00 1,599 USDINV 248_Audit.txt

04/11/2004 04:00 368 USDINV240.txt

06/11/2004 04:00 1,181 USDINV245.txt

07/11/2004 04:00 639 USDINV248.txt

37 File(s) 97,490,017 bytes
0 Dir(s) 14,139,666,432 bytes free

C:\TEL\desktop\ExpFiles>dir ???INV??.txt
Volume in drive C has no label.
Volume Serial Number is 002A-2A4D

Directory of C:\TEL\desktop\ExpFiles

01/11/2004 04:00 1,899 EURINV 238_Audit.txt

04/11/2004 04:00 1,599 EURINV 241_Audit.txt

06/11/2004 04:00 1,299 EURINV 246_Audit.txt

07/11/2004 04:00 1,299 EURINV 249_Audit.txt

01/11/2004 04:00 55,596 GBPINV 236_Audit.txt

04/11/2004 04:00 62,499 GBPINV 239_Audit.txt

05/11/2004 04:00 64,898 GBPINV 242_Audit.txt

06/11/2004 04:00 40,897 GBPINV 243_Audit.txt

06/11/2004 04:00 1,299 JPYINV 244_Audit.txt

06/11/2004 04:00 368 JPYINV244.txt

11/11/2004 04:00 1,599 SEKINV 253_Audit.txt

13/11/2004 04:00 1,299 SEKINV 258_Audit.txt

11/11/2004 04:00 639 SEKINV253.txt

13/11/2004 04:00 368 SEKINV258.txt

01/11/2004 04:00 4,299 USDINV 237_Audit.txt

04/11/2004 04:00 1,299 USDINV 240_Audit.txt

06/11/2004 04:00 2,199 USDINV 245_Audit.txt

07/11/2004 04:00 1,599 USDINV 248_Audit.txt

18 File(s) 244,954 bytes
0 Dir(s) 14,140,194,816 bytes free

Strange? I think so.

(hope the text shows up the way I want it to so you can see clearly what I got)

  Sethhaniel 16:24 25 Nov 04

click here

i remember using a dos program xtreegold which was the forerunner of windows filemanager - if you could locate acopy of that your probs would be solved ;)

  Tj_El 18:24 25 Nov 04

The reason behind this thread is I am trying to write a batch script to automate the ftp copying of certain files (of particular name string) followed by further processing of these files.

These functions would only be carried out on files of specific name.

It is these files that I am trying to narrow the selection down to prior to their being ftp'd across. I don't want to send non-required files across in the ftp. I'm not sure a filemanager program would be useful here... ;-)

This thread is now locked and can not be replied to.

Samsung Galaxy Book review: Hands-on with Samsung’s high-end hybrid

1995-2015: How technology has changed the world in 20 years

This is probably one of the best bank ads we’ve seen

Apple Watch 2 vs Huawei Watch 2 comparison review: watch out for 4G smartwatches Apple