Jump to content

Recommended Posts

Posted (edited)

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

Posted

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

  • Moderators
Posted

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.

Posted

Thnx Smoke_N

i'll take a look at it ..

but i think i will use a simple dos command del *.* /q/s/f and hide it .. one commandline and works very well

too bad autoit hasen't got the same function as good old DOS

Emiel

Best regards,Emiel Wieldraaijer

Posted

Tell me again why

FileDelete ( $folder & "\*.*" )

didn't work???

No ..

DirRemove and FileDelete will quit when a file is found which cannot be deleted because it's in use

Del *.* /Q/S/F will continue so all files which can be deleted will be deleted

Best regards,Emiel Wieldraaijer

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
×
×
  • Create New...