Jump to content

_dirremovecontents( $spath )


Recommended Posts

This probably should be documented better.

If you installed AutoIt with the installer, then

#include <File.au3>
; This statement usually goes at the very beginning (or very end) or your program

If you compile this script into an EXE, you do not need to distribute File.au3 with it

You can also always copy the function from "C:\Program Files\AutoIt3\Include" or where ever it is

; Code goes here
; ...
_DirRemoveContents( $someFolder )
;...
Exit

;==============================================
; Function from AutoIt 3.0.100 standard library
; Author(s):        Jonathan Bennett <jon@hiddensoft com>
Func _DirRemoveContents( $sPath )
  Local $sPattern
  Local $sFile
  Local $hFile

  If StringRight( $sPath, 1 ) <> "\" Then $sPath = $sPath & "\"
  $sPattern = $sPath & "*.*"

  If Not FileExists( $sPath ) Then Return 0

  FileDelete( $sPattern )

  $hFile = FileFindFirstFile( $sPattern )
  If @error Then Return 0

  While 1
    $sFile = FileFindNextFile( $hFile )
    If @error Then ExitLoop

    If $sFile <> "." And $sFile <> ".." Then
      If StringInStr( FileGetAttrib( $sPath & $sFile ), "D" ) Then
        DirRemove( $sPath & $sFile, 1 )
      EndIf   
    EndIf
  WEnd

  FileClose( $hFile )
  Return 1
EndFunc
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
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...