Jump to content

What I'm i doing wrong?


Recommended Posts

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.

$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 by Muzzikap
Link to post
Share on other sites

Sry, but are you sure if this file/dir can be deleted manually?  :idiot:

<{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 post
Share on other sites

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 by SlimShady
Link to post
Share on other sites

:idiot:

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 :D

FileClose($Zoek) << added this line
if DirRemove  ( $dir ) = 0 then MsgBox(0, "why o why dont remove", $dir);
Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...