RogerL Posted February 23, 2008 Share Posted February 23, 2008 I wish to test if a USB drive is empty. (My first post and I'm fairly new to AutoIt so please be gentle) I have found that DriveSpaceFree and DriveSpaceTotal return the same value if it is empty so I can use this in my code but I tried first to use FileFindFirstFile and found that for empty subdirs it returns @error = 1, but 0 for root. Is there something wrong in my code below or is it a bug? ; before running this - formated drive L:, checked Windows hadn't created any hidden files ; #include <file.au3> $logFile = @TempDir & "\test.log" _FileWriteLog ($logFile, DriveSpaceFree("L:") & ", " & DriveSpaceTotal("L:\")); same = empty?! $file = FileFindFirstFile("L:\*.*") _FileWriteLog ($logFile, "$file = " & $file & ", @error = " & @error) DirCreate("L:\Temp") $file = FileFindFirstFile("L:\Temp\*.*") _FileWriteLog ($logFile, "$file = " & $file & ", @error = " & @error) _FileWriteLog ($logFile, DriveSpaceFree("L:") & ", " & DriveSpaceTotal("L:\")); differ by size of dir #cs contents of $logFile: 2008-02-23 17:51:56 : 1936.84375, 1936.84375 2008-02-23 17:21:00 : $file = -1, @error = 0 <------------------ shouldn't this be 1? 2008-02-23 17:21:00 : $file = -1, @error = 1 2008-02-23 18:06:19 : 1936.8125, 1936.84375 #ce Link to comment Share on other sites More sharing options...
MHz Posted February 23, 2008 Share Posted February 23, 2008 I cannot say yes as being a bug. "Returns -1 if error occurs. If the Folder is empty the @error is set to 1." Technically the root is not a folder. And MSDN are unclear to the error response other then invalid handle which the -1 return basically covers. So should it be @error = 1, I will pass on that one . Link to comment Share on other sites More sharing options...
RogerL Posted February 24, 2008 Author Share Posted February 24, 2008 Technically the root is not a folder.Did Microsoft change the rules when they renamed directories as folders (to help make computing more friendly for Joe Public)?When did the root directory become not a directory? Isn't it just a special directory in that it can't be 'RMDIR'ed or 'MKDIR'ed and doesn't have a parent.Anyway I would be grateful for the recommended way to test for the root directory to be empty. Link to comment Share on other sites More sharing options...
therks Posted February 24, 2008 Share Posted February 24, 2008 I guess you could actually iterate through FileFindNextFile and just count how many loops you do until it stops. If it's 0, then tadaa, empty folder. $handle = FileFindFirstFile('u:\*.*') $count = 0 While 1 FileFindNextFile($handle) If @error Then ExitLoop $count += 1 WEnd FileClose($handle) ConsoleWrite($count & ' files in folder') My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
Zedna Posted February 24, 2008 Share Posted February 24, 2008 Anyway I would be grateful for the recommended way to test for the root directory to be empty.Look here Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
MHz Posted February 24, 2008 Share Posted February 24, 2008 Did Microsoft change the rules when they renamed directories as folders (to help make computing more friendly for Joe Public)?Not sure what set of rules you are referring to.A directory is a index/listing. A folder is an virtual container that can have files or folders within. They are not the same though some times they seem to be the same. Link to comment Share on other sites More sharing options...
RogerL Posted February 24, 2008 Author Share Posted February 24, 2008 A folder is an virtual container that can have files or folders within.So why isn't the root directory a folder as it can have files and folders within it? Link to comment Share on other sites More sharing options...
MHz Posted February 24, 2008 Share Posted February 24, 2008 So why isn't the root directory a folder as it can have files and folders within it?Because it is a root of a drive that has a directory but it is not a folder. Simply stating that both can contain files or folders does not make them the same so quit trying to make them the same.There are 2 registry keys that exist that allow you to add items to your context menu for this example. If I wanted to add an item into the registry for right click on a folder. Would I choose the "folder" key or the "directory" key. If you can tell me the answer and why the choice, then you may realize the difference. There is also a key named "drive". Those keys exist because there is a difference between them.A telephone directory is not a telephone folder. Get the point? Link to comment Share on other sites More sharing options...
RogerL Posted March 5, 2008 Author Share Posted March 5, 2008 (edited) Because it is a root of a drive that has a directory but it is not a folder. Simply stating that both can contain files or folders does not make them the same so quit trying to make them the same.There are 2 registry keys that exist that allow you to add items to your context menu for this example. If I wanted to add an item into the registry for right click on a folder. Would I choose the "folder" key or the "directory" key. If you can tell me the answer and why the choice, then you may realize the difference. There is also a key named "drive". Those keys exist because there is a difference between them.A telephone directory is not a telephone folder. Get the point? I aplogise for the delay in replying. I'll be honest I didn't understand your post and have been agonizing about how to reply. I'm not good at writing English. So often forum posts get misinterpreted.Not sure what context menu you are refering to. I am not a windows programmer and using the registry to explain the difference between folders and directories is a bit 'back to front'There were no differences between directories and folders in MS-DOS. There were none in WIndows 3.1. Did MS introduce folders in Win95? I don't remember.I would appreciate you pointing me to material on the web tha can help me undertand how MS use the two terms internally.As a layman I understand that a telephone directory is a list of telephone numbers and I would guess that in this context a telephone folder would be the cover.I am surprised, given your explanation, that AutoIt has no Folder Functions. At the very least one might expect DirCreate to be FolderCreate.Finally I would apprecitate it if thought could be given to amending the FileFindFirstFile help to say that - "it does not return @error = 1 if the root directory is empty as it is not strictly a 'folder' " (or amending the code if it is possible as users might expect it to)Kind Regards,Roger Edited March 5, 2008 by RogerL Link to comment Share on other sites More sharing options...
RogerL Posted March 5, 2008 Author Share Posted March 5, 2008 I guess you could actually iterate through FileFindNextFile and just count how many loops you do until it stops. If it's 0, then tadaa, empty folder. $handle = FileFindFirstFile('u:\*.*') $count = 0 While 1 FileFindNextFile($handle) If @error Then ExitLoop $count += 1 WEnd FileClose($handle) ConsoleWrite($count & ' files in folder')Thank you Saunders very much. That does it for me. (I apologise for the delay in replying, been waiting till I replied to MHz) Link to comment Share on other sites More sharing options...
RogerL Posted March 5, 2008 Author Share Posted March 5, 2008 Look hereThanks for pointing me to that Zedna. (I apologise for the delay in replying, been waiting till I replied to MHz)If the root dir is empty the array doesn't display but I couldn't find return values that allowed me to test this condition in the code. Anyway I'm happy to go with Saunders solution so no need for more help on this unless you want to. Link to comment Share on other sites More sharing options...
MHz Posted March 5, 2008 Share Posted March 5, 2008 I would appreciate you pointing me to material on the web tha can help me undertand how MS use the two terms internally.Honestly Roger, I think you are smart enough to research on your own. You are correct about the telephone directory though I never considered a cover to be a folder. And FolderCreate maybe more correct but using Dir* for everything folder or directory related saves dilution of function prefixes and confusion like trying to explain the difference between those two items in this thread. By the sounds of your reply, you do know the difference so I do not understand your objective reply of using sarcasm. Link to comment Share on other sites More sharing options...
RogerL Posted March 6, 2008 Author Share Posted March 6, 2008 (edited) By the sounds of your reply, you do know the difference so I do not understand your objective reply of using sarcasm.No sarcasm was intended. Would appreciate you quoting the piece you interpret as sarcasm so I can avoid it in the future. I started my last post saying "So often forum posts get misinterpreted"... Edited March 6, 2008 by RogerL Link to comment Share on other sites More sharing options...
MHz Posted March 6, 2008 Share Posted March 6, 2008 No sarcasm was intended. Would appreciate you quoting the piece you interpret as sarcasm so I can avoid it in the future. I started my last post saying "So often forum posts get misinterpreted"...The Windows 3.1 seemed usual to have mentioned for it's primitive design so perhaps that invoked my feeling of sarcasm in use. I will retract the remark and put it as a misunderstanding. I am glad the others have shown you a solution to your issue so I wish you luck with the fix. 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