Muzzikap Posted January 17, 2005 Share Posted January 17, 2005 (edited) What is the reason that when i try to delete a directory the directory won't be deleted? What am I doing wrong? I have tried FileRecycle , DirRemove but these two commands just simply don't seen to work I keep getting the messagebox: MsgBox(0, "Failed removing dir", "Failed removing dir");Please go easy on my way of scripting. It's my first Autoit script.expandcollapse popup$StartDir= "F:\automatiseren op pc\oefenen\Download\" $Submaps= "" Global $dir_list[50]; Main(); Func Main() $i = 0; while 1 $dir = $StartDir & $Submaps $Zoek = FileFindFirstFile( $dir & "*.*") If $Zoek = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($Zoek) If @error Then if NietinArray($file) then MsgBox(0, "Remove dir and restart search", $dir); if DirRemove ( $dir) = 0 then MsgBox(0, "Failed removing dir", "Failed removing dir"); $Submaps= "" ExitLoop EndIf EndIf if $file = "." OR $file = ".." then ContinueLoop if (StringInStr($dir & "*",FileGetAttrib ($file), "D") AND NietinArray($file)) then $t = FileGetTime($dir & $file, 1); If @error Then $Submaps=$Submaps& $file & "\" MsgBox(0, "Directory found", $file); ExitLoop EndIf endif if (StringInStr($dir & "*",FileGetAttrib ($file), "N"))then MsgBox(0, "Found file in dir", $file); if StringInStr($file, "par2") then CheckRar($dir) Reset(); ExitLoop Else $dir_list[$i] = $file; MsgBox(0, "Dir to array", $file); $i = $i + 1; Endif EndIf WEnd FileClose($Zoek) WEND EndFunc Edited January 17, 2005 by Muzzikap Link to comment Share on other sites More sharing options...
Josbe Posted January 17, 2005 Share Posted January 17, 2005 Sry, but are you sure if this file/dir can be deleted manually? Returns 0 if there is an error removing the directory (or if directory does not exist). AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta Link to comment Share on other sites More sharing options...
Muzzikap Posted January 17, 2005 Author Share Posted January 17, 2005 Sry, but are you sure if this file/dir can be deleted manually? <{POST_SNAPBACK}> I can delete/move the directory using windows explorer. I guess that is enough to see that i can remove the dir manually?if it doesn't work this way please explain to me how i can see if i can delete this folder manually Link to comment Share on other sites More sharing options...
Josbe Posted January 17, 2005 Share Posted January 17, 2005 hmm... change this line: if DirRemove ( "$dir") to if DirRemove ( $dir) AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta Link to comment Share on other sites More sharing options...
Muzzikap Posted January 17, 2005 Author Share Posted January 17, 2005 hmm...change this line:if DirRemove ( "$dir")toif DirRemove ( $dir)<{POST_SNAPBACK}>Thanks I changed it. but that wasn't the solution. I still got the same problem Link to comment Share on other sites More sharing options...
SlimShady Posted January 17, 2005 Share Posted January 17, 2005 (edited) Quote from the help file/online docs:recurse [optional]Use this flag to specify if you want to delete sub-directories too. 0 = (default) do not remove files and sub-directories 1 = remove files and subdirectories (like the DOS DelTree command)So change:if DirRemove ( $dir)to:if DirRemove ($dir, 1) Edited January 17, 2005 by SlimShady Link to comment Share on other sites More sharing options...
Muzzikap Posted January 17, 2005 Author Share Posted January 17, 2005 Quote from the help file/online docs:So change:if DirRemove ( $dir)to:if DirRemove ($dir, 1)<{POST_SNAPBACK}>already tried that one aswell. tomorrow i will add some commentary to my script and then post it at this tread. Link to comment Share on other sites More sharing options...
Josbe Posted January 17, 2005 Share Posted January 17, 2005 @Slim: Yes, but only will delete the file.@Muzzikap: Probably, the directory cannot deleted, because it's being handled for FileFindFirstFile(). AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta Link to comment Share on other sites More sharing options...
SlimShady Posted January 17, 2005 Share Posted January 17, 2005 @Slim: Yes, but only will delete the file.<{POST_SNAPBACK}> @Muzzikap: Probably, the directory cannot deleted, because it's being handled for FileFindFirstFile().<{POST_SNAPBACK}>Possible... Link to comment Share on other sites More sharing options...
Muzzikap Posted January 18, 2005 Author Share Posted January 18, 2005 Possible...<{POST_SNAPBACK}>Thanxz Josbe & Slimshady,Josbe you were right it kept returning an error because it's being handled for FileFindFirstFile().So with a little modification this code works FileClose($Zoek) << added this line if DirRemove ( $dir ) = 0 then MsgBox(0, "why o why dont remove", $dir); 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