Jump to content
Sign in to follow this  
Emiel Wieldraaijer

DirRemove Question

Recommended Posts

Emiel Wieldraaijer

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


Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites
ChrisL

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

Share this post


Link to post
Share on other sites
Emiel Wieldraaijer

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

Share this post


Link to post
Share on other sites
ChrisL

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

Share this post


Link to post
Share on other sites
pixels75

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

Share this post


Link to post
Share on other sites
Emiel Wieldraaijer

thnx guys

@pixels75

you forgot to mention

DirRemove($folder & "\" & $file, 1)

Edited by Emiel Wieldraaijer

Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites
pixels75

thnx guys

@pixels75

you forgot to mention

DirRemove($folder & "\" & $file, 1)

You're right ! I've done that quickly :whistle:

Share this post


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
Sign in to follow this  

×