Jump to content

DirRemove Question


Recommended Posts

Is it possible to remove all files and subfolder but not the folder itself ?

c:\deleteme

c:\deleteme\1

c:\deleteme\2

c:\deleteme\3

c:\deleteme\4

DirRemove ("c:\deleteme", 1) delete also c:\deleteme

Thnx

Emiel

Cant you just recreate it after?

DirRemove ("c:\deleteme", 1)
DirCreate("c:\deleteme")
Edited by ChrisL
Link to comment
Share on other sites

Yeah i could.. but i don't want to ..

In the help

DirRemove ( "path" [, recurse] )

Parameters

path Path of the directory to remove.

recurse [optional] Use this flag to specify if you want to delete sub-directories too.

0 = (default) do not remove files and sub-directories -> if this is default why not remove the DirRemove command ???????

1 = remove files and subdirectories (like the DOS DelTree command)

Best regards,Emiel Wieldraaijer

Link to comment
Share on other sites

Yeah i could.. but i don't want to ..

Oh OK, hows this then?

Clean ("c:\deleteme")

Func Clean($current)

    Local $search = FileFindFirstFile($current & "\*.*")
    While 1
        Dim $file = FileFindNextFile($search)
        If @error Or StringLen($file) < 1 Then ExitLoop
        If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") Then

                FileDelete ($current & "\" & $file)

        EndIf
        If StringInStr(FileGetAttrib($current & "\" & $file), "D") Then
            
            DirRemove ($current & "\" & $file,1)
            
        EndIf
    WEnd
    FileClose($search)

EndFunc

Oh and this 0 = (default) do not remove files and sub-directories -> if this is default why not remove the DirRemove command ???????

Is so that if the Directory is not empty it doesn't get deleted, 1 forces it to delete even if it's not empty

Edited by ChrisL
Link to comment
Share on other sites

Yeah i could.. but i don't want to ..

In the help

DirRemove ( "path" [, recurse] )

Parameters

path Path of the directory to remove.

recurse [optional] Use this flag to specify if you want to delete sub-directories too.

0 = (default) do not remove files and sub-directories -> if this is default why not remove the DirRemove command ???????

1 = remove files and subdirectories (like the DOS DelTree command)

Func Flush($folder)
    Local $search, $file, $attrib

    $search = FileFindFirstFile($folder & "\*.*")
    If $search <> -1 Then
        While 1
            $file = FileFindNextFile($search)
            If @error Then ExitLoop
            $attrib = FileGetAttrib($folder & "\" & $file)
            If StringInStr($attrib, "D") Then
                DirRemove($folder & "\" & $file)
            Else
                FileDelete($folder & "\" & $file)
            EndIf
        Wend
    EndIf
EndFunc
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...