ChrisL Posted September 30, 2005 Share Posted September 30, 2005 I can't understand this, but if I do a file copy recursive and I encounter an empty folder I'm left with open filehandles.. does anyone know why this is please.. Thanks expandcollapse popup#include <file.au3> #include <Array.au3> #include <GUIConstants.au3> $fileHandle = fileFindFirstFile("D:\Upload\*.lac") if ($fileHandle <> -1) then endif if (@error = 1) then Else $file = fileFindNextFile($fileHandle) ENDIF if ($file = "." or $file = "..") then Else $Folder = StringtrimRight ($File, 4) Endif FileClose($FileHandle) StartCopy ("d:\Upload\" & $Folder & "\", "\\bay1server\upload\"& $Folder) ;MsgBox (0,"","d:\Upload\" & $Folder & "\" & "\\bay1server\upload") FileCopy ("d:\Upload\" & $File, "\\bay1server\upload\" & $File ) DirMove ("d:\Upload\" & $Folder, "d:\Upload\done\", 1) FileMove ("d:\Upload\" & $File, "d:\Upload\done\", 1) Func StartCopy ($Var1, $Var2) If StringRight($Var1, 1) = '\' Then $Var1 = StringtrimRight( $Var1, 1 ) If StringRight($Var2, 1) <> '\' Then $Var2 = $Var2 & '\' $Var3 = $Var1 FileSetAttrib ( $Var2 , "-R" , 1 ) processFolder($Var1, $Var2, $Var3) FileSetAttrib ( $Var2, "-R" , 1 ) ;Sleep (1000) EndFunc func processFolder($path, $Destination, $Fixed) local $fileHandle, $file, $dirHandle, $dir local const $FILESPEC = "*.*" debug("Starting with " & $path) debug("Going to search for " & $path & "\" & $FILESPEC) $fileHandle = fileFindFirstFile($path & "\" & $FILESPEC) if ($fileHandle <> -1) then while (1) $file = fileFindNextFile($fileHandle) if (@error = 1) then exitLoop if ($file = "." or $file = "..") then continueLoop $file = $path & "\" & $file if (isFolder($file,$Destination, $Fixed)) then continueLoop copy($file, $Destination, $Fixed) wEnd endif fileClose($fileHandle) debug("Going to search for subfolders") $dirHandle = fileFindFirstFile($path & "\*.*") if ($dirHandle <> -1) then while (1) $dir = fileFindNextFile($dirHandle) if (@error = 1) then exitLoop if ($dir = "." or $dir = "..") then continueLoop $dir = $path & "\" & $dir if (not(isFolder($dir,$Destination, $Fixed))) then continueLoop debug("Found subfolder " & $dir) processFolder($dir, $Destination, $Fixed) wEnd endIf fileClose($dirHandle) debug ($DirHandle) endFunc func isFolder($path,$Destination, $Fixed) if stringInStr(fileGetAttrib($path), "D") then $stripped =stringreplace($Path, $Fixed &"\","") DirCreate ( $Destination & $Stripped ) debug ("Path " & $Path) debug ("Creat Dir " & $Destination & $Stripped) return 1 else return 0 Endif endFunc func copy($text,$Destination, $Fixed) $NewDir = $Destination $stripped =stringreplace($text, $fixed &"\","") FileCopy ($text, $NewDir & $Stripped,1) endFunc func debug($text) MsgBox (0,"Debug", $Text) endFunc [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
ChrisL Posted October 2, 2005 Author Share Posted October 2, 2005 Someone please help me. It seems to be when it goes after a new directory that is empty, because it is exiting out of the isfolder function and then the variable is trashed, but the filehandle is still open. How can I get round this? Thanks [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
Developers Jos Posted October 2, 2005 Developers Share Posted October 2, 2005 Someone please help me.It seems to be when it goes after a new directory that is empty, because it is exiting out of the isfolder function and then the variable is trashed, but the filehandle is still open. How can I get round this?ThanksCould you be more explicit about what the problem is you are having ?Which variable gets trashed ?Why do you say that a FileHandle isn't closed ? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
ChrisL Posted October 2, 2005 Author Share Posted October 2, 2005 Could you be more explicit about what the problem is you are having ?Which variable gets trashed ?Why do you say that a FileHandle isn't closed ?It isn't able to move the empty folders after it has copied all of the files.It should look for a file called 1234.lac (for example) then search the folder with the same name, copy all of the files and folders to another location on another computer (shared folder) then move all of the copied files to a done folder locally. But it can not move the empty folders as there is still a file lock on them. As soon as the program exits then the lock is released.I think that it is Dirhandle thats the problem, when it changes dir to search for files and doesn't find any files in the empty folder it exits the isfolder loop and leaves the filehandle open on the empty dir. (I THINK!) At least I think thats whats happeningI added some more lines into the program and made it output to a file.I have attached them if anyone can work out where I have gone wrong.Thanks [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
Developers Jos Posted October 2, 2005 Developers Share Posted October 2, 2005 Think you hit a BUG here. I am not that familiar with this piece of code but it looks like a Handle isn't freed when there is no file found. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
ChrisL Posted October 2, 2005 Author Share Posted October 2, 2005 Think you hit a BUG here.I am not that familiar with this piece of code but it looks like a Handle isn't freed when there is no file found.Yeah.. thats my problem! [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
ChrisL Posted October 4, 2005 Author Share Posted October 4, 2005 Anyone else have any thoughts on this please? Is it a bug or is it something I'm doing.. Thanks [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
Developers Jos Posted October 4, 2005 Developers Share Posted October 4, 2005 Anyone else have any thoughts on this please?Is it a bug or is it something I'm doing..ThanksBugreport was filed with the possible solution and JP will integrate it in the upcoming BETA .. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
DavoGotland Posted October 14, 2005 Share Posted October 14, 2005 (edited) Anyone else have any thoughts on this please?Is it a bug or is it something I'm doing..ThanksHi. First comment on this forum.I've used AutoIt for maybe a year now, and it's great. However, I just today coded a script that's supposed to compare files on your harddrive. If two files are of the exact same size, they will be written to a text-file. After running the program you can read the text-file, and locate files that might be duplicates.To do this, I use a recursive function that's called with the name of the directory it should check. If the function stumbles on a folder, it calls itself with the folder name. Now, it's quoting time. Here's what the help-file says about the command FileOpen:"Up to 64 files can be open simultaneously by one AutoIt script."I've checked my code with MsgBox:es, and all the "$whatever = FileFindFirstFile ( $somedirectory )" are "FileClose ( $whatever )", and all the files I write to or read from are closed during functions as well. Still, the program ends if I check a folder that has more then 64 folders inside it.And I don't mean that the folder tree is more then 64 folders deep. I mean that if I have a folder with 70 folders inside it, all in the same folder, my code won't work. So it seems "Up to 64 files can be opened during the course of one AutoIt script" would be a more correct way of explaining it.. The only logical reason for this that I could come up with was that the FileClose-function ins't doing what it's supposed to, so I came here. Any ideas anyone? Is it the same problem as the one explained above? Has it been solved in version 3.1?If there's any use for it, I'm happy to post my code, just ask. However, if there's need for posting my code, I need to know one thing. Are <TAB> removed from the code? I've noticed that some code-segments are indented, and some are not on this forum. I'd like it for my code to be indented.//David, Sweden Edited October 14, 2005 by DavoGotland Link to comment Share on other sites More sharing options...
Developers Jos Posted October 14, 2005 Developers Share Posted October 14, 2005 Is it the same problem as the one explained above? Has it been solved in version 3.1?If there's any use for it, I'm happy to post my code, just ask. However, if there's need for posting my code, I need to know one thing. Are <TAB> removed from the code? I've noticed that some code-segments are indented, and some are not on this forum. I'd like it for my code to be indented.There was a bug with Handles whenever FileFindFirst() encountered an Empty directory. This is fixed in 3.1.1.81.Try your script with the latest BETA and see if this solves your issue... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. 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