Jump to content

Small Problem with flushing a folder


Recommended Posts

Hi All,

I want to flush (delete the entire content of) a folder.

Let say the Internet Explorer Cache Folder of the Current User

some files are in use so the flush command ends.. without erasing everything else which can be deleted

i'm using the following code..

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, 1)
        Else
          FileDelete($folder & "\" & $file)
        EndIf
     WEnd
  EndIf
EndFunc

is there an error in code .. or isn't it possible

Thnx

Emiel

Edited by Emiel Wieldraaijer

Best regards,Emiel Wieldraaijer

Link to comment
Share on other sites

Func _Flush($folder)

Local $search, $file, $attrib

If $search = FileFindFirstFile($folder & "\*.*") ;Why if? isn't this missing a then too...

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, 1)

Else

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

EndIf

WEnd

EndIf

EndFunc

Link to comment
Share on other sites

  • Moderators

Look for _FileListToArrayEx or _FileListToArrayNew in the example forum... there you can recurse or use exclude methods.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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...