WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: George Vagenas on July 06, 2014, 04:41:37 PM

Title: Wildcarding with FileItemize & DirItemize
Post by: George Vagenas on July 06, 2014, 04:41:37 PM
In this situation the results are not consistent:
Code (winbatch) Select

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.
Title: Re: Wildcarding with FileItemize & DirItemize
Post by: Deana on July 07, 2014, 10:49:14 AM
It does appear that FileItemize and DirItemize default wildcards are handled differently. Adding IntControl (91, 1, 0, 0, 0) seems to resolve the issue.
Title: Re: Wildcarding with FileItemize & DirItemize
Post by: td on July 08, 2014, 09:48:13 AM
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 dose not support the old MSDOS pattern. However, you can get wildcard matches by simply using '*' instead of '*.*'.    In fact, 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.   
Title: Re: Wildcarding with FileItemize & DirItemize
Post by: td on July 08, 2014, 01:05:03 PM
I should have added that 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.   
Title: Re: Wildcarding with FileItemize & DirItemize
Post by: George Vagenas on July 08, 2014, 11:51:32 PM
Thank you both.  Deana's trick works for the most part but I did some testing and found that some pattern results will be wrong.  The folders I'm interested in are created by another program and contain files that I want to consolidate into one folder.  Seeing as DirItemize wildcarding works just fine when there are no "."s in the folder names I wrote a simple script to "Undot" the folders to solve my problem.