Jump to content

Recommended Posts

Posted

Hi, :D

I need a progress bar for deleting files.(EMPTY FOLDER)

So i need to combine this scripts: BUT HOW

» Directory copy with progress bar «

CODE

AutoItSetOption("MustDeclareVars", 1)

Dim $n

ProgressOn("Dir Copy With Progress", "", "Scanning . . .")

$n = _DirCopyWithProgress("D:\Test1\*.au3", "D:\Test2", 1)

Sleep(5000)

ProgressOff()

Func _DirCopyWithProgress($sFileSpec, $sDestDir, $nOverwrite)

Local $sSourceDir

Local $nSourceLen

Local $sRootDir

Local $hSearch

Local $sFile

Local $sPathList = "*"

Local $sFileList

Local $aCopyList

Local $nTotalSize

Local $nSize

Local $i

$i = StringInStr($sFileSpec, "\", 0, -1)

$sSourceDir = StringLeft($sFileSpec, $i)

$nSourceLen = StringLen($sSourceDir)

$sFileSpec = StringRight($sFileSpec, StringLen($sFileSpec)-$i)

If Not FileExists($sDestDir) Then

If Not DirCreate($sDestDir) Then Return 0

EndIf

If StringRight($sDestDir, 1) <> "\" Then $sDestDir = $sDestDir & "\"

$sRootDir = $sSourceDir

While 1

$hSearch = FileFindFirstFile($sRootDir & "*.*")

If $hSearch > -1 Then

$sFile = FileFindNextFile($hSearch)

While Not @error

If $sFile <> "." And $sFile <> ".." Then

If StringInStr(FileGetAttrib($sRootDir & $sFile), "D") Then

$sPathList = $sPathList & $sRootDir & $sFile & "*"

Else

If _MatchFilePattern($sFile, $sFileSpec) Then

$sFileList = $sFileList & StringTrimLeft($sRootDir, $nSourceLen) & "*" & $sFile & "*"

$i = FileGetSize($sRootDir & $sFile)

$nTotalSize = $nTotalSize + $i

$sFileList = $sFileList & $i & "*"

EndIf

EndIf

EndIf

$sFile = FileFindNextFile($hSearch)

Wend

FileClose($hSearch)

EndIf

If $sPathList = "*" Then ExitLoop

$sPathList = StringTrimLeft($sPathList, 1)

$sRootDir = StringLeft($sPathList, StringInStr($sPathList, "*")-1) & "\"

$sPathList = StringTrimLeft($sPathList, StringInStr($sPathList, "*")-1)

Wend

If $sFileList <> "" Then

$aCopyList = StringSplit($sFileList, "*")

For $i = 1 To $aCopyList[0]-2 Step 3

If Not FileExists($sDestDir & $aCopyList[$i]) Then DirCreate($sDestDir & $aCopyList[$i])

If FileCopy($sSourceDir & $aCopyList[$i] & $aCopyList[$i+1], _

$sDestDir & $aCopyList[$i] & $aCopyList[$i+1], $nOverwrite) Then

$nSize = $nSize+$aCopyList[$i+2]

ProgressSet(Int(($nSize/$nTotalSize)*100), $aCopyList[$i+1] & @CRLF & "From: " & $aCopyList[$i])

EndIf

Next

EndIf

If $nSize = $nTotalSize Then

Return 1

Else

Return 0

EndIf

EndFunc

Func _MatchFilePattern($sFileName, $sPattern)

Local $i

Local $c

Local $n

Local $nMatch = 1

For $i = 1 To StringLen($sPattern)

$c = StringMid($sPattern, $i, 1)

If $c <> "*" Then

$n = StringInStr($sFileName, $c)

If $n = 0 Then

$nMatch = 0

ExitLoop

Else

$sFileName = StringTrimLeft($sFileName, $n)

EndIf

EndIf

Next

Return $nMatch

EndFunc

» Empty folder func «

CODE

Func EmptyFolder($FolderToDelete)

$AllFiles = _FileListToArray($FolderToDelete, "*", 0)

If $Debug Then MsgBox(0, "", $FolderToDelete)

If IsArray($AllFiles) Then

If $Debug Then

_ArrayDisplay($AllFiles, $FolderToDelete)

EndIf

For $i = 1 To $AllFiles[0]

FileDelete($FolderToDelete & "\" & $AllFiles[$i])

DirRemove($FolderToDelete & "\" & $AllFiles[$i], 1)

Next

EndIf

EndFunc ;==>EmptyFolder

But how, please help me.

[font="Comic Sans MS"][size="4"]My UDF's:[/size]1. _ChooseIconAnd this is just the beginning[/font]

Posted

Hope this help you.

#include <File.au3>
$DIR = FileSelectFolder("Select","")
If Not @error Then
    $FILE = _FileListToArray($DIR,"*",1)
    If IsArray($FILE) Then
        ProgressOn("Folder Remove",$DIR)
        For $INDEX = 1 To $FILE[0]
            ProgressSet($INDEX*100/$FILE[0],$FILE[$INDEX])
            FileDelete($DIR & "\" & $FILE[$INDEX])
            Sleep(250)
        Next
        ProgressOff()
    EndIf
EndIf
Posted

$sFolder = FileSelectFolder("Select folder", "")
If @error Then Exit

ProgressOn("Dir delete with progress", "", "Scanning . . .")
$iFiles = _GetFileCount($sFolder)
_DeleteFilesProgress($sFolder, $iFiles)
ProgressOff()

Func _GetFileCount($sFolder, $bRecursive = True)
    Local $iNumFiles = 0, $hFindFile, $sFile, $sFilepath
    $hFindFile = FileFindFirstFile($sFolder & "\*")
    While 1
        $sFile = FileFindNextFile($hFindFile)
        If @error Then ExitLoop
        $sFilepath = $sFolder & "\" & $sFile
        If $bRecursive And StringInStr(FileGetAttrib($sFilepath), "D", 2) <> 0 Then $iNumFiles += _GetFileCount($sFilepath, $bRecursive)
        $iNumFiles += 1
    WEnd
    Return $iNumFiles
EndFunc

Func _DeleteFilesProgress($sFolder, $iTotalFiles, $iNumFiles = 0, $bRecursive = True)
    Local $hFindFile, $sFile, $sFilepath
    
    $hFindFile = FileFindFirstFile($sFolder & "\*")
    While 1
        $sFile = FileFindNextFile($hFindFile)
        If @error Then ExitLoop
        $sFilepath = $sFolder & "\" & $sFile
        If $bRecursive And StringInStr(FileGetAttrib($sFilepath), "D", 2) <> 0 Then
            $iNumFiles = _DeleteFilesProgress($sFilepath, $iTotalFiles, $iNumFiles, $bRecursive)
            ProgressSet($iNumFiles / $iTotalFiles * 100, "Deleting: " & $sFile)
            DirRemove($sFilepath)
        Else
            ProgressSet($iNumFiles / $iTotalFiles * 100, "Deleting: " & $sFile)
            FileDelete($sFilepath)
        EndIf
        $iNumFiles += 1
    WEnd
    Return $iNumFiles
EndFunc

Posted

This will delete also dirs.

#include <File.au3>
$DIR = FileSelectFolder("Select","")
If Not @error Then
    $FILE = _FileListToArray($DIR)
    If IsArray($FILE) Then
        Dim $PATH[5]
        ProgressOn("Folder Remove",$DIR)
        For $INDEX = 1 To $FILE[0]
            ProgressSet($INDEX*100/$FILE[0],$FILE[$INDEX])
            _PathSplit($DIR & "\" & $FILE[$INDEX],$PATH[1],$PATH[2],$PATH[3],$PATH[4])
            If $PATH[4] <> "" Then
                FileDelete($DIR & "\" & $FILE[$INDEX])
            Else
                DirRemove($DIR & "\" & $FILE[$INDEX],1)
            EndIf
            Sleep(250)
        Next
        ProgressOff()
    EndIf
EndIf

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...