Wildcarding with FileItemize & DirItemize

Started by George Vagenas, July 06, 2014, 04:41:37 PM

Previous topic - Next topic

George Vagenas

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.
Thanks

George

Deana

It does appear that FileItemize and DirItemize default wildcards are handled differently. Adding IntControl (91, 1, 0, 0, 0) seems to resolve the issue.
Deana F.
Technical Support
Wilson WindowWare Inc.

td

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.   
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

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.   
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

George Vagenas

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.
Thanks

George