Sign in to follow this  
Followers 0
Emiel Wieldraaijer

Small Problem with flushing a folder

9 posts in this topic

#1 ·  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

Share this post


Link to post
Share on other sites



DirRemove:

From the help file:

Some dir attributes can make the removal impossible.

don't know if that helps

Share this post


Link to post
Share on other sites

thnx for the answer ..

i am aware of that so i've changed the above question .. a bit ..

Emiel


Best regards,Emiel Wieldraaijer

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

sorry ..

didn't belong there..

copy - paste error

Emiel


Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Tell me again why

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

didn't work???

Share this post


Link to post
Share on other sites

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

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  
Followers 0