Jump to content

help find flaw in my function?


Recommended Posts

I have a function that I use to catch invalid paths. Only thing is, it seems to be letting through some folders that used to exist, but are deleted. Here's the code:

Func _ValidPath($path)
  ;filter out obvious junk
  If StringLen($path) < 2 Then Return False

  Local $sysDrive = StringLeft(@WindowsDir, 2)
  Local $drive = StringLeft($path, 2)
  If $sysDrive = $drive Then
    Return FileExists($path)
  EndIf

  Local $driveType = DriveGetType($drive)
  If @error Then Return False
  Switch $driveType

    Case "Unknown"
    Return False

    Case "Network"
    If DriveStatus($drive) = "Invalid" Then Return False

    Case "CDROM", "Removable"
    If DriveStatus($drive) = "NotReady" Then Return False

  EndSwitch

  Return FileExists($path)
EndFunc   ;==>_ValidPath

I'm calling it like

If _ValidPath($arrayOfPaths[$x]) Then

do_somthing()

EndIf

The only things that come to mind is either

FileExists() is sensitive to file system flushing

or buffering, or something bad is happening because

I'm mixing Return False and Return FileExists() which

returns 0 or 1.

Or, I'm getting unexpected result because of If statements

inside Switch cases? I'm not sure what's happening. Anyone

see any side effect or bug?

Link to comment
Share on other sites

The folders that are not detected as deleted, are they all on a fixed drive?

Yes. It's on the main hd. I'm wondering if it's a shell thing. I'm running Vista64 and a lot of times I have to use LockHunter on this system. It's tough to tell because I don't get a lot of user feedback, but the utility that uses the function hasn't gotten any bug reports. Maybe it's just a Vista64 thing. Guess the next thing I'll do is try to recreate the error on Windows 7 32 bit.

If I find anything out I'll post. I'm using AutoIt v. 3.3.0.0 btw.

Link to comment
Share on other sites

Thanks to everyone who replied. I found the bug in my code. It's not related to checking a valid path. The ListBox has an input with a little incremental search routine. Even though I checked for a valid path before adding to the ListBox, I didn't filter out invalid paths in the array. So when I did the incremental search, if I got a match, I added the path back into the ListBox. Easy not to notice it isn't there if you have 60 entries and stuff is jumping while you type. But I did MsgBox through the loop and the "bad" directory wasn't getting though _ValidPath() or FileExists().

In the past I was cleaning out all the invalid paths when reading the saved folder names on program startup, but since the utility is often set to run on Windows startup before network drives are mapped, I put it off until later. I never explicitly cleaned out the array.

Thanks for the help finding that bug. >_<

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...