WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Miscellaneous

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Wildcarding with FileItemize and DirItemize

 Keywords: FileItemize DirItemize Wild Card Wildcard File Mask IntControl 91 

Question:

In this situation the results are not consistent:
DirChange('C:\')
DirName = 'TestWild'
Cnt = 0
While DirExist(DirName)
   Cnt = Cnt+1
   DirName = DirName : Cnt
EndWhile

DirMake(DirName)
DirChange(DirName)

DirMake('Te.st')
FilePut('Te.st.txt', '0')

For Cnt = 1 To 3
   DirMake('Te.st' : Cnt)
   FilePut('Te.st' : Cnt : '.txt', '0')
Next
Files = FileItemize('Te.st*.*')
Dirs = DirItemize('Te.st*.*')    ; Returns ""
FileCnt = ItemCount(Files, @TAB)
DirCnt = ItemCount(Dirs, @TAB)

; Result ---> FileCnt==4, DirCnt==0
Pause(`DEBUG PAUSE`, StrCat(`FileCnt = `, FileCnt, @CRLF, `DirCnt = `, DirCnt))

DirRemove('Te.st')
For Cnt = 1 To 3
   DirRemove('Te.st' : Cnt)
Next
FileDelete('*.*')

DirChange('C:\')
DirRemove(DirName)

:CANCEL
Return
But if you change "Te.st" to "Test" they are. I came across this problem when processing some folders that had a "." in the folder name. The folders being processed had a common base name but not all folders were being processed. When I removed the "." from the folder names all the folders were processed as expected.Modify message

Answer:

It does appear that FileItemize and DirItemize default wildcards are handled differently. The '*.*' wildcard pattern is an old file matching pattern for MSDOS that was carried over to some win32 APIs and will match everything no matter how many periods are in the name. The default matching algorithm for DirItemize does not support the old MSDOS pattern. However, you can get wildcard matches by simply using '*' instead of '*.*'. IntControl 91 can be used to modify the behavior of wildcard matching in both FileItemize and DirItemize. Hoever, it is probably better to use the single asterisk when you can for DirItemize because IntControl(91, 1, 0, 0, 0) uses the OS's shell pattern matching which has it's own set of bugs and quirks.

There is a simple rule for wildcard pattern matching involving the period character and either DirItemize or FileItemize. That rule being that you can't have more period characters in your wildcard pattern than exist in each name you want to match.


Article ID:   W18508
Filename:   Wildcarding with FileItemize and DirItemize .txt
File Created: 2014:07:09:09:21:58
Last Updated: 2014:07:09:09:21:58