Go Back  Xtreme Visual Basic Talk > General Discussion > Tech Discussions > Dir function - wildcard bug


Reply
 
Thread Tools Display Modes
  #1  
Old 05-22-2011, 12:21 AM
Mathimagics's Avatar
Mathimagics Mathimagics is offline
Algorithms 'R' Us

Forum Leader
* Guru *
 
Join Date: Jun 2002
Location: Canberra
Posts: 4,123
Default Dir function - wildcard bug


Has anybody else come across this problem?

Command window DIR command with wildcards sometimes reports an unmatched item. Since it and VB6 use the same Win32 API FindFirstFile the bug occurs in VB6 Dir$() function just the same way:

  • s=dir$(agdlf & "arb*4*")
    do: ?S: s = dir$(): loop while len(s)
  • Arbitrary_GDL_4.lst
    Arbitrary_GDL_4.txt
    Arbitrary_GDL_6.txt
  • s=dir$(agdlf & "arb*1*")
    do: ?S: s = dir$(): loop while len(s)
  • Arbitrary_GDL_10.txt
    Arbitrary_GDL_10_Invalid.txt
    Arbitrary_GDL_10_Pending.txt
    Arbitrary_GDL_4.lst
__________________
Cogito, ergo codo
Reply With Quote
  #2  
Old 05-22-2011, 12:22 AM
Mathimagics's Avatar
Mathimagics Mathimagics is offline
Algorithms 'R' Us

Forum Leader
* Guru *
 
Join Date: Jun 2002
Location: Canberra
Posts: 4,123
Default

That's on Windows 7 (Home). The directory contains many other similar files with different digits but the wildcard bug only occurs for 1 and 4.

I presume the Del command uses the same wildcard processor so I'm glad I didn't find this bug the hard way
__________________
Cogito, ergo codo
Reply With Quote
  #3  
Old 05-22-2011, 06:40 AM
dilettante's Avatar
dilettante dilettante is offline
Underclocked lifestyle

Forum Leader
* Guru *
 
Join Date: Feb 2005
Location: Michigan, USA
Posts: 4,347
Default

The comments for FindFirstFile (scroll down) suggest there are lots of traps awaiting the unsuspecting. Could be an artifact of many layers of backward compatibility attempts over three decades.
Reply With Quote
  #4  
Old 05-22-2011, 09:22 AM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

I think the answer is probably explained in this Raymond Chen post. Unfortunately he didn't explain how the algorithm that was adopted after that one is abandoned. But I'd be willing to bet things get wonky when there's multiple wildcards involved. I seem to recall having trouble with multiple * wildcards in the past and ultimately giving up. Maybe "arb*4.*" will work better? From the given context it doesn't look like there's anything between the number and the dot. I'd expect your wildcard to pick up "Arbitrary_GDL_40.txt" and I'm not sure if that's what you wanted either.

In .NET I'd say use the EnumerateFiles() method for efficiency and a regex for greater accuracy. That's not to say every now and then regex doesn't make me go bonkers. In VB6 I'm sure there's a similar trick.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #5  
Old 05-22-2011, 10:25 AM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,726
Default

Quote:
Originally Posted by Mathimagics View Post
That's on Windows 7 (Home). The directory contains many other similar files with different digits but the wildcard bug only occurs for 1 and 4.

I presume the Del command uses the same wildcard processor so I'm glad I didn't find this bug the hard way
Since you're using 7, try FindFirstFileEx with FindExInfoBasic (also works on server 08 R2). It appears to omit 8.3 names, so maybe they won't match either. Unfortunately this doesn't help with code running on previous unsupported OSes.
__________________
Quis custodiet ipsos custodues.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->