viewpoint-particle

Author Topic: Wildcarding with FileItemize & DirItemize  (Read 3466 times)

George Vagenas

  • Full Member
  • ***
  • Posts: 102
Wildcarding with FileItemize & DirItemize
« on: July 06, 2014, 04:41:37 pm »
In this situation the results are not consistent:
Code: Winbatch
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

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Wildcarding with FileItemize & DirItemize
« Reply #1 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.
Deana F.
Technical Support
Wilson WindowWare Inc.

td

  • Tech Support
  • *****
  • Posts: 3992
    • WinBatch
Re: Wildcarding with FileItemize & DirItemize
« Reply #2 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.   
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

  • Tech Support
  • *****
  • Posts: 3992
    • WinBatch
Re: Wildcarding with FileItemize & DirItemize
« Reply #3 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.   
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

George Vagenas

  • Full Member
  • ***
  • Posts: 102
Re: Wildcarding with FileItemize & DirItemize
« Reply #4 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.
Thanks

George