Jump to content
Priorityboy

help howto del folder with progress

Recommended Posts

Priorityboy

I want to delete some folders in Appdata and while i'm deleting it, there will be the status showed like this. 

#include <File.au3>

DeleteFolderContent("@AppDataDir & ".minecraft",1") ; > Set "C:\Users\Administrator\AppData\Roaming\Mikrotik" Folder user appdata <<< Change always

$DIR = FileSelectFolder("Select","") ; > Set "C:\Users\Administrator\AppData\Roaming\Mikrotik" Folder user appdata change here
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

 

Or if you want to specify the folders without clicking anything to choose it, let it run itself by using this kind of code.

#RequireAdmin
$sFolder = FileSelectFolder("Select folder", "") ; > Set "C:\Users\Administrator\AppData\Roaming\Mikrotik" Folder user appdata
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

 

Share this post


Link to post
Share on other sites
water

The title tells me that you are asking for help. But I do not find a question in your thread :huh:


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Priorityboy

yes, i'am find no topic

Edited by Priorityboy

Share this post


Link to post
Share on other sites
Priorityboy

Does anybody know how to write the script for deleting the folders in any other ways? You can suggest it here. 

Share this post


Link to post
Share on other sites
water

Does the first code snippet you posted work for you?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.