MilesAhead Posted August 4, 2009 Share Posted August 4, 2009 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? My Freeware Page Link to comment Share on other sites More sharing options...
Authenticity Posted August 4, 2009 Share Posted August 4, 2009 Can you post a few lines of the array content? Link to comment Share on other sites More sharing options...
Scriptonize Posted August 4, 2009 Share Posted August 4, 2009 The folders that are not detected as deleted, are they all on a fixed drive? If you learn from It, it's not a mistake Link to comment Share on other sites More sharing options...
MilesAhead Posted August 4, 2009 Author Share Posted August 4, 2009 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. My Freeware Page Link to comment Share on other sites More sharing options...
MilesAhead Posted August 4, 2009 Author Share Posted August 4, 2009 Well, there goes that theory!! I get the same thing on Windows 7 32 bit. So for some reason stuff is getting by _ValidPath() or some other side effect is happening. I'll try to make a test case that does it. My Freeware Page Link to comment Share on other sites More sharing options...
Scriptonize Posted August 4, 2009 Share Posted August 4, 2009 I made a small test on XP-SP3 and I'm also using AutoIT V 3.3.0.0 I used a small array of 10 folders. All is working as it should. If you learn from It, it's not a mistake Link to comment Share on other sites More sharing options...
MilesAhead Posted August 4, 2009 Author Share Posted August 4, 2009 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. >_< My Freeware Page Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now