Jump to content
KickStarter15

Deleting subfolder with same byte size and retain specific subfolder

Recommended Posts

KickStarter15
Posted (edited)

Hi Experts,

I've been searching for almost a week now and I don't get the results I want. I was stocked right now and don't know how to proceed with my codes.

Here's my problem:

1. I want to get all folder names inside a certain path say "D:\programs\For Archiving\", from that path there are lots of folders with sub-folders in it (see attached folder name), example first folder name is "abc12345" and from that folder, it has sub-folders named "000003825, 0000003575, 0000003047, 0000003048, 0000003031 etc...".

2. Once a first folder found, then first "delete the sub-folders with the same byte size and retain only one" then next is to delete other sub-folders that was not underlined in my screenshot attached (sub folder).

3. After the two items above then loop back the script and process the next folder same thing of what was did in first folder "abc12345" and so on.... until done checking all folders found in this path "D:\programs\For Archiving\".

4. Lastly, once done with the processing, there should be log for all the deletion made inside a text file named "archive.log".

 

Hope someone can help me with this Experts, really appreciated. Please let me know if you want more information or details.

- Folders found from this path "D:\programs\For Archiving\":

FoldarNames.PNG

- Sub-folders found from the first folder "abc12345":

SubFolder of abc12345.png

 

Here's my code:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>
#include <FileConstants.au3>
#include <WinAPIFiles.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#Include <GUIEdit.au3>
#Include <ScrollBarConstants.au3>

$read=FileRead(@ScriptDir & "\Archive.log")

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Archiving Tool", 612, 419, 268, 226)
GUISetBkColor(0xABB1B4)
$Group1 = GUICtrlCreateGroup(" Folders ", 17, 8, 569, 97)
$RadioArchive = GUICtrlCreateRadio("For Archiving", 42, 32, 81, 17)
$RadioQual = GUICtrlCreateRadio("For Quality", 218, 32, 97, 17)
$RadioChckng = GUICtrlCreateRadio("For Checking", 418, 32, 97, 17)
$RadioIss = GUICtrlCreateRadio("For Issue", 418, 64, 113, 17)
$RadioPrf = GUICtrlCreateRadio("For Proof", 218, 64, 73, 17)
$RadioULoad = GUICtrlCreateRadio("For Upload", 42, 64, 105, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$CheckboxExclude = GUICtrlCreateCheckbox("Exclude Folders", 29, 121, 89, 25)
GUICtrlSetBkColor($CheckboxExclude, $COLOR_RED)
$CheckboxInclude = GUICtrlCreateCheckbox("Include Folders", 118, 121, 89, 25)
GUICtrlSetBkColor($CheckboxInclude, $COLOR_GREEN)
$Fdelte = GUICtrlCreateButton("Folder Delete", 497, 116, 89, 33)
$LogView = GUICtrlCreateButton("View Log", 14, 373, 97, 33)
$ExitBut = GUICtrlCreateButton("Exit", 497, 368, 89, 33)
$EditMe = GUICtrlCreateEdit("", 17, 150, 568, 217, BitOr($GUI_SS_DEFAULT_EDIT, $ES_READONLY))
GUICtrlSetData($EditMe,$read)
GUICtrlSetColor($EditMe, $COLOR_RED)
;~ GUICtrlSetState($EditMe, $GUI_DISABLE)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $ExitBut
            Exit
         Case $LogView
;~          MsgBox(0,"",@ScriptDir & "\Archive.log")
            ShellExecute(@ScriptDir & "\Archive.log")
         Case $Fdelte
            Local $iSize = DirGetSize("D:\Programs\")
            MsgBox($MB_SYSTEMMODAL, "", "Folder Size: " & Round($iSize / 1024 / 1024) & "MB")
    EndSwitch
WEnd

 

Thank you in advance Experts!

KS15

Edited by KickStarter15
Missed to add the code...

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
Subz

Didn't really understand the Gui, but basically you can do something like below, I would recommend using ChooseFileFolder by Melba23 for creating your Exclusion list in your Gui and then just pass that information to the _SubfolderUpdate() function

#include <Array.au3>
#include <File.au3>
#include <ChooseFileFolder.au3>

Global $g_sLogFile = @ScriptDir & "\Archive.log"
Global $g_hLogFile = FileOpen($g_sLogFile, 9)

FileWrite($g_hLogFile, "#### Archive Log Start: " & @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " ###" & @CRLF)

Local $_sInitialPath = "D:\Programs\For Archiving"
Local $aLevel2_Exclusions[6]
    $aLevel2_Exclusions[0] = $_sInitialPath & "\abc12345\1000000000"
    $aLevel2_Exclusions[1] = $_sInitialPath & "\abc12345\1000003571"
    $aLevel2_Exclusions[2] = $_sInitialPath & "\abc12345\1000003237"
    $aLevel2_Exclusions[3] = $_sInitialPath & "\abc12345\0000000000"
    $aLevel2_Exclusions[4] = $_sInitialPath & "\abc12345\1000003827"
    $aLevel2_Exclusions[5] = $_sInitialPath & "\abc12345\1000003047"

;~ _DemoData()
;~ Exit

_SubfolderUpdate("D:\Programs\For Archiving", $aLevel2_Exclusions)

FileWrite($g_hLogFile, "#### Archive Log End: " & @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " ###" & @CRLF)
FileClose($g_hLogFile)


Func _SubfolderUpdate($_sInitialPath = "D:\Programs\For Archiving", $_aLevel2_Exclusions = "")
    ;~ Create an array of subfolders below initial path (no recursion)
    Local $aLevel1_SubFolders = _FileListToArrayRec($_sInitialPath, "*", 2, 0, 0, 2)
        If @error Then Exit MsgBox(16, "Error: " & $_sInitialPath, "Error occurred creating Folder List with " & $_sInitialPath)
    ;~ Loop through the first level subfolders
    For $i = 1 To $aLevel1_SubFolders[0]
        ;~ Create an array of subfolders within each first level folder
        $aLevel2_SubFolders = _FileListToArrayRec($aLevel1_SubFolders[$i], "*", 2, 0, 0, 2)
            If @error Then ContinueLoop
        _ArrayColInsert($aLevel2_SubFolders, 1)
        For $j = 1 To $aLevel2_SubFolders[0][0]
            $aLevel2_SubFolders[$j][1] = DirGetSize($aLevel2_SubFolders[$j][0])
        Next
        _ArraySort($aLevel2_SubFolders, 1, 1, 0, 1)
        For $j = 1 To $aLevel2_SubFolders[0][0]
            If $j = $aLevel2_SubFolders[0][0] Then ExitLoop
            If $aLevel2_SubFolders[$j][1] = $aLevel2_SubFolders[$j + 1][1] Then
                If IsArray($_aLevel2_Exclusions) Then
                    If _ArraySearch($_aLevel2_Exclusions, $aLevel2_SubFolders[$j + 1][0]) = -1 Then
                        ;~ The next folder in the level 2 folder array is not excluded from deletion, so delete.
                        _DirRemove($aLevel2_SubFolders[$j + 1][0], 1)
                    ElseIf _ArraySearch($_aLevel2_Exclusions, $aLevel2_SubFolders[$j][0]) = -1 Then
                        ;~ The current folder in the level 2 folder array is not excluded from deletion, so delete.
                        _DirRemove($aLevel2_SubFolders[$j][0], 1)
                    Else
                        MsgBox(32, "Unknown", "Both folders have the same folder size, but both in exclusion list.")
                    EndIf
                Else
                    ;~ Exclusion List not set so remove ANY folders with the same size.
                    _DirRemove($aLevel2_SubFolders[$j + 1][0], 1)
                EndIf
            EndIf
        Next
    Next
EndFunc

Func _DirRemove($_sFolderPath, $_bRecurse = 0)
    Local $hDirRemove = DirRemove($_sFolderPath, $_bRecurse)
    Switch $hDirRemove
        Case 1
            FileWrite($g_hLogFile, @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " : Success: Removing Folder: " & $_sFolderPath & @CRLF)
        Case 0
            FileWrite($g_hLogFile, @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " : Failure: Removing Folder: " & $_sFolderPath & @CRLF)
    EndSwitch
EndFunc

Func _DemoData()
    For $i = 0 To UBound($aLevel2_Exclusions) - 1
        DirCreate($aLevel2_Exclusions[$i])
        FileWrite($aLevel2_Exclusions[$i] & "\Test.txt", Random(0, 110) & @CRLF)
    Next
    For $i = 1 To 5
        $sSubDir2 = $_sInitialPath & "\abc12345" & "\" & Random($i & 000000000, 9999999999, 1)
        DirCreate($sSubDir2)
        FileWrite($sSubDir2 & "\Test.txt", Random(0, 110) & @CRLF)
    Next
    For $i = 0 To 10
        $sSubDir1 = $_sInitialPath & "\" & Random($i & 000000000, 9999999999, 1)
        DirCreate($sSubDir1)
        For $j = 1 To 5
            $sSubDir2 = $sSubDir1 & "\" & Random($j & 000000000, 9999999999, 1)
            DirCreate($sSubDir2)
            FileWrite($sSubDir2 & "\Test.txt", Random(0, 10) & @CRLF)
        Next
    Next
EndFunc

 

Share this post


Link to post
Share on other sites
KickStarter15

@Subz,

Thanks, but I don't get yet the complexity of your code (maybe later :sweating:) but when I tested the code it was deleting the folders with the same bytes size which is okay, however, other folders were not deleted considering that these folders should remain in that path "1000000000, 1000003571, 1000003237, 0000000000, 1000003827, 1000003047" I mean, all folders that was not declared in our exclusion should be deleted.:>

15 hours ago, Subz said:

Didn't really understand the Gui,

:D It's a selection type radio button that when the user selected a specific folder to be deleted. For the edit box in that GUI, all files being deleted will be shown in the editbox, exclusion and inclusion checkboxes is where we can declared the excluded folder to be deleted. If excluded is ticked, then there are folders to be excluded but when included is ticked then all folders from that specific filename will be deleted.

 

15 hours ago, Subz said:

I would recommend using ChooseFileFolder by Melba23

I got error in opening this file #include <ChooseFileFolder.au3> can I have the include?

 

Thank you in advance.....^_^


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
Subz

"I mean, all folders that was not declared in our exclusion should be deleted."

So what is the point of comparing folder sizes if you're going to delete the folder anyway?  Why not just delete all folders that aren't in the exclusions and then compare folder sizes of the exclusions?  In that case if two folders that are in the exclusions list have the same folder size, how do you decide which folder to delete?

You can download ChooseFileFolder (not actually utilized in the code above) from https://www.autoitscript.com/forum/topic/125293-choosefilefolder-new-version-16-feb-17/
ChooseFileFolder will allow you to use checkbox in explorer like view to create your exclusion list.

Anyway you would need to clarify the compare folder size and exclusion list as I'm not sure exactly what you want to do.

 

Share this post


Link to post
Share on other sites
KickStarter15
4 minutes ago, Subz said:

So what is the point of comparing folder sizes if you're going to delete the folder anyway? 

Yahh, sorry for that. Folder with the same byte size must be included in our exclusion, I mean we already have our exclusion declared right so when there is/are folder with the same byte size then one of that folder should be excluded in deleting as well.:sweating:

 

6 minutes ago, Subz said:

In that case if two folders that are in the exclusions list have the same folder size, how do you decide which folder to delete?

Either of the the folder will be deleted and retain only one, anyway they are duplicated so they are the same files inside that folder.:D

 

8 minutes ago, Subz said:

Anyway you would need to clarify the compare folder size and exclusion list as I'm not sure exactly what you want to do.

Sorry Subz, hope my above two explanations will suffice your inquiry.:>


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
Subz

So can you tell us what the code I posted above is missing, in terms of removing duplicate sized folders, without removing the exceptions?

Share this post


Link to post
Share on other sites
KickStarter15
Posted (edited)

@Subz,

Yup and there are folders declared in the exclusion but was being deleted due to duplicate byte size (see attached) "1000003571" and "1000003047" was declared in exclusion list.

exclusion.PNG

Deleted.PNG

 

And the below screenshot are the list of folders to retain, highlighted in red are the duplicates and with green check are the exclusion list. The rest of these folders must be deleted.

ListOfFolders.PNG

 

Your code will now perform the deletion of same byte size and exclude some folders but won't able to remove the rest of these folders found.:sweating:

 

Thanks...

 

P.S. Subz, BTW, after deleting/checking subfolders of abc12345 or after done processing the first folder, the code should proceed to the next folder from the path given. See below sample folder filenames, these folder with different folder names must be checking and archive same on the first folder.

image.png.3f8cd1be9397a05155a1f71374513b08.png

Edited by KickStarter15
Adding screenshots, missed.

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
KickStarter15
Posted (edited)

@Subz

I talked to my Superiors and discussed to them the most easiest way in archiving folders from that path and they agreed that it's okay to delete all folders regardless with the byte size and retain only the folders that was/were declared in exclusion list, however, they will be the one to input the exclusion list in an .ini text file.

"Config.ini" would be like this:

[ArichivingExclusion]
000003825
0000003575
0000003047
0000003048
0000003031

[QualityExclusion]
000003825
0000003575
0000003047
0000003048
0000003031

[IssueExclusion]
000003825
0000003575
0000003047
0000003048
0000003031

[UploadExclusion]
000003825
0000003575
0000003047
0000003048
0000003031

These folders being declared will be excluded in deleting subfolders. Well maybe in that way it makes it more convenient:> rather than complicate things.

Hope it's okay with you subz. Thanks...

Edited by KickStarter15

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
Subz

Question: Could any folders of the first subfolder be the same?
Example:
D:\Programs\For Archiving\abc1234567\000003825
D:\Programs\For Archiving\\zxy1234567\000003825

If not then you could configure your ini like below, when we use _FileListToArrayRec we just exclude all folders with that name under D:\Programs\For Archiving.

[D:\Programs\For Archiving]
000003825=
0000003575=
0000003047=
0000003048=
0000003031=

[D:\Programs\Quality]
000003825=
0000003575=
0000003047=
0000003048=
0000003031=

[D:\Programs\Issue]
000003825=
0000003575=
0000003047=
0000003048=
0000003031=

[D:\Programs\Upload]
000003825=
0000003575=
0000003047=
0000003048=
0000003031=

The following code shows how to return list of folders that will be deleted, can you check if this would work for you?

#include <Array.au3>
#include <File.au3>

Local $sConfigFile = @ScriptDir & "\config.ini"
Local $aSectionNames = IniReadSectionNames($sConfigFile)
    If @error Then Exit MsgBox(16, "Config.ini Error", "Error reading: " & $sConfigFile)
For $i = 1 To $aSectionNames[0]
    If FileExists($aSectionNames[$i]) = 0 Then ContinueLoop
    $aSectionData = IniReadSection($sConfigFile, $aSectionNames[$i])
        If @error Then ContinueLoop
    $aFolderList = _FileListToArrayRec($aSectionNames[$i], "*|"& _ArrayToString($aSectionData, ";", 1, -1, ";", 0, 0), 2, 1, 0, 2)
        If @error Then ContinueLoop
    _ArrayDisplay($aFolderList, "All these folders would be deleted.")
Next

 

Share this post


Link to post
Share on other sites
KickStarter15
7 minutes ago, Subz said:

Question: Could any folders of the first subfolder be the same?
Example:
D:\Programs\For Archiving\abc1234567\000003825
D:\Programs\For Archiving\\zxy1234567\000003825

Yup possible they have the same name.

 

8 minutes ago, Subz said:

The following code shows how to return list of folders that will be deleted, can you check if this would work for you?

#include <Array.au3>
#include <File.au3>

Local $sConfigFile = @ScriptDir & "\config.ini"
Local $aSectionNames = IniReadSectionNames($sConfigFile)
    If @error Then Exit MsgBox(16, "Config.ini Error", "Error reading: " & $sConfigFile)
For $i = 1 To $aSectionNames[0]
    If FileExists($aSectionNames[$i]) = 0 Then ContinueLoop
    $aSectionData = IniReadSection($sConfigFile, $aSectionNames[$i])
        If @error Then ContinueLoop
    $aFolderList = _FileListToArrayRec($aSectionNames[$i], "*|"& _ArrayToString($aSectionData, ";", 1, -1, ";", 0, 0), 2, 1, 0, 2)
        If @error Then ContinueLoop
    _ArrayDisplay($aFolderList, "All these folders would be deleted.")
Next

It show's the list of folders to be deleted but was not deleting them. Also, if config "[D:\Programs\For Archiving]" is selected then only that selected radio should be deleted. There are radio buttons in my script for interactive selection on what to delete. Same like below snippet combined from your code::sweating:

If GUICtrlRead($RadioArchiving) = 1 Then
      $msg = MsgBox(4,"Warnig!", "Are you sure with " & "'For Archiving'" & " being selected?")
        If $msg = 6 Then
            $aArray = _FileListToArrayRec(@ScriptDir & "\For Archiving\", "*", 2, 1)
            $Msg = ''
         For $i = 0 To UBound($aArray) - 1
            $iSize = DirGetSize(@ScriptDir & "\For Archiving\" & $aArray[$i],0)
            $Msg &= "Folder found..." & $aArray[$i] & " with byte size of " & "'" & Round($iSize / 1024 / 1024) & "MB'"& "...." & @CRLF

            FileWrite($g_hLogFile, "#### Archive Log Start: " & @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " ###" & @CRLF)

            Local $_sInitialPath = $aArray
            Local $aLevel2_Exclusions[6]
               $aLevel2_Exclusions[0] = $_sInitialPath & $aArray[$i] & "\1000000000"
               $aLevel2_Exclusions[1] = $_sInitialPath & $aArray[$i] & "\1000003571"
               $aLevel2_Exclusions[2] = $_sInitialPath & $aArray[$i] & "\1000003237"
               $aLevel2_Exclusions[3] = $_sInitialPath & $aArray[$i] & "\0000000000"
               $aLevel2_Exclusions[4] = $_sInitialPath & $aArray[$i] & "\1000003827"
               $aLevel2_Exclusions[5] = $_sInitialPath & $aArray[$i] & "\1000003047"

            _SubfolderUpdate(@ScriptDir & "\For Archiving\", $aLevel2_Exclusions)

            FileWrite($g_hLogFile, "#### Archive Log End: " & @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " ###" & @CRLF)
            FileClose($g_hLogFile)
         Next
            GUICtrlSetData($EditMe,"Folder Count: " & $Msg) ; this will show the folders in editbox not to worry about
        Else
         Return
        EndIf
     EndIf

 

Overall testing, it show's the subfolders to be deleted subz but this includes those should be excluded.


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
Subz

So the last piece of code only shows the folders that should be deleted, it doesn't actually delete anything, what I wanted to know was the list correct?  On my system none of the excluded folders appear in the ArrayDisplay, is that the same for you?

Share this post


Link to post
Share on other sites
KickStarter15

@Subz,

I have attached a screenshot, yup those in the list were not shown except for the first item listed in the exclusion (highlighted). The rest are okay.:sweating:

image.png.6ef92884cbd1542e39a4d877d79ecc2a.png


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
Subz

Sorry have a big project on at the moment, only got the following so far:

#include <Array.au3>
#include <File.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>
#include <FileConstants.au3>
#include <WinAPIFiles.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#Include <GUIEdit.au3>
#Include <ScrollBarConstants.au3>

Global $g_sLogFile = @ScriptDir & "\Archive.log"
Global $g_hLogFile = FileOpen($g_sLogFile, 1)
Global $g_iLogFlag = 2

Global $g_sConfigFile = @ScriptDir & "\config.ini"
    If FileExists($g_sConfigFile) = 0 Then Exit MsgBox(16, "Config Error", "Unable to find: " & $g_sConfigFile & @CRLF & "Exiting...")

Global $g_idEdit
_ArchiveTool()
Func _ArchiveTool()
    Local $sSelection
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Archiving Tool", 612, 419, 268, 226)
    GUISetBkColor(0xABB1B4)
    $Group1 = GUICtrlCreateGroup(" Folders ", 17, 8, 569, 97)
    $hRadioStart = GUICtrlCreateDummy()
    $RadioArchive = GUICtrlCreateRadio("For Archiving", 42, 32, 81, 17)
    $RadioQual = GUICtrlCreateRadio("For Quality", 218, 32, 97, 17)
    $RadioChckng = GUICtrlCreateRadio("For Checking", 418, 32, 97, 17)
    $RadioIss = GUICtrlCreateRadio("For Issue", 418, 64, 113, 17)
    $RadioPrf = GUICtrlCreateRadio("For Proof", 218, 64, 73, 17)
    $RadioULoad = GUICtrlCreateRadio("For Upload", 42, 64, 105, 17)
    $hRadioEnd = GUICtrlCreateDummy()
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $CheckboxExclude = GUICtrlCreateCheckbox("Exclude Folders", 29, 121, 89, 25)
    GUICtrlSetBkColor($CheckboxExclude, $COLOR_RED)
    $CheckboxInclude = GUICtrlCreateCheckbox("Include Folders", 118, 121, 89, 25)
    GUICtrlSetBkColor($CheckboxInclude, $COLOR_GREEN)
    $Fdelte = GUICtrlCreateButton("Folder Delete", 497, 116, 89, 33)
    $LogView = GUICtrlCreateButton("View Log", 14, 373, 97, 33)
    $ExitBut = GUICtrlCreateButton("Exit", 497, 368, 89, 33)
    $g_idEdit = GUICtrlCreateEdit("", 17, 150, 568, 217, BitOr($GUI_SS_DEFAULT_EDIT, $ES_READONLY))
    _GUICtrlEdit_SetLimitText($g_idEdit, 64000)
    GUICtrlSetData($g_idEdit,FileRead($g_sLogFile))
    _GUICtrlEdit_LineScroll($g_idEdit, 0, _GUICtrlEdit_GetLineCount($g_idEdit))

    GUICtrlSetColor($g_idEdit, $COLOR_RED)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE, $ExitBut
                FileClose($g_hLogFile)
                Exit
             Case $LogView
    ;~          MsgBox(0,"",@ScriptDir & "\Archive.log")
                ShellExecute($g_sLogFile)
            Case $Fdelte
                For $iRadio = ($hRadioStart + 1) To ($hRadioEnd - 1)
                    If BitAND(GUICtrlRead($iRadio), $GUI_CHECKED) = $GUI_CHECKED Then
                        $sSelection = GUICtrlRead($iRadio, 1)
                        _LogWrite("Selected: " & $sSelection)
                        ExitLoop
                    EndIf
                Next
                If $sSelection = "" Then
                    _LogWrite("No Folder were selected for deletion.")
                    ContinueLoop
                EndIf
                _FolderCleanup($sSelection)
        EndSwitch
    WEnd
EndFunc

Func _FolderCleanup($_sSelection)
    Local $sRootFolder = IniRead($g_sConfigFile, "Root Folders", $_sSelection, "")
        If FileExists($sRootFolder) = 0 Then Return _LogWrite("Folder Selection Error" & @CRLF & $g_sConfigFile & @CRLF & "Section Name: [Source Folders]" & @CRLF & "Section Key:  " & $_sSelection & @CRLF & "Returned an unknown folder path")
    Local $aFolderExclusions = IniReadSection($g_sConfigFile, $_sSelection)
        If @error Then Return _LogWrite("Config.ini Error" & @CRLF & "Exclusions error reading section " & $_sSelection & " section may not exist or is empty")
    Local $aLevel1_SubFolders = _FileListToArrayRec($sRootFolder, "*|" & _ArrayToString($aFolderExclusions, ";", 1, -1, ";", 0, 0), 2, 0, 0, 2)
        If @error Then Return _LogWrite("File List Error: " & _FileListToArrayRecReturn($_sSelection, @extended))
    For $i = 1 To $aLevel1_SubFolders[0]
        $aLevel2_SubFolders = _FileListToArrayRec($aLevel1_SubFolders[$i], "*|" & _ArrayToString($aFolderExclusions, ";", 1, -1, ";", 0, 0), 2, 0, 0, 2)
            If @error Then ContinueLoop
        For $j = 1 To $aLevel2_SubFolders[0]
            _DirRemove($aLevel2_SubFolders[$j], 1)
        Next
    Next
EndFunc

Func _DirRemove($_sFolderPath, $_bRecurse = 0)
    Local $hDirRemove = DirRemove($_sFolderPath, $_bRecurse)
    Switch $hDirRemove
        Case 1
            _LogWrite(@MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " : Success: Removing Folder: " & $_sFolderPath)
        Case 0
            _LogWrite(@MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " : Failure: Removing Folder: " & $_sFolderPath)
    EndSwitch
EndFunc

Func _LogWrite($_sLogData, $_iLogFlag = $g_iLogFlag)
    Switch $_iLogFlag
        Case 1
            _GUICtrlEdit_Scroll($g_idEdit, $SB_SCROLLCARET)
            _GUICtrlEdit_AppendText ($g_idEdit, $_sLogData & @CRLF)
        Case 2
            FileWrite($g_hLogFile, $_sLogData & @CRLF)
            _GUICtrlEdit_Scroll($g_idEdit, $SB_SCROLLCARET)
            _GUICtrlEdit_AppendText ($g_idEdit, $_sLogData & @CRLF)
    EndSwitch
EndFunc

Func _FileListToArrayRecReturn($_sFilePath, $_iExtended)
    Switch $_iExtended
        Case 1
            Return $_sFilePath & " - Path not found or invalid"
        Case 2
            Return "Invalid Include parameter"
        Case 3
            Return "Invalid Exclude parameter"
        Case 4
            Return "Invalid Exclude_Folders parameter"
        Case 5
            Return "Invalid $iReturn parameter"
        Case 6
            Return "Invalid $iRecur parameter"
        Case 7
            Return "Invalid $iSort parameter"
        Case 8
            Return "Invalid $iReturnPath parameter"
        Case 9
            Return "No files/folders found"
    EndSwitch
EndFunc

 

  • Like 1

Share this post


Link to post
Share on other sites
KickStarter15

@Subz,

Thanks, man and no worries^_^... However, I can't make it work due to below log generated.

image.png.c9f6eb098ff2cb80feadf12d0e53fc29.png

 

This is the format of my .ini file (as you suggested):

image.png.26eac6cdf32b9246e22192257c011c40.png

 

Could not trace the cause of error :sweating:  sorry...


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
Subz

Sorry forgot to post the ini, I thought I'd match it to your radio buttons.

[Root Folders]
For Archiving = D:\Programs\For Archiving
For Quality = D:\Programs\For Quality
For Checking = D:\Programs\For Checking
For Issue = D:\Programs\For Issue
For Proof = D:\Programs\For Proof
For Upload = D:\Programs\For Upload

[For Archiving]
000003825=
0000003575=
0000003047=
0000003048=
0000003031=

[For Quality]
000003825=
0000003575=
0000003047=
0000003048=
0000003031=

[For Checking]
000003825=
0000003575=
0000003047=
0000003048=
0000003031=

[For Issue]
000003825=
0000003575=
0000003047=
0000003048=
0000003031=

[For Proof]
000003825=
0000003575=
0000003047=
0000003048=
0000003031=

[For Upload]
000003825=
0000003575=
0000003047=
0000003048=
0000003031=

 

  • Thanks 1

Share this post


Link to post
Share on other sites
KickStarter15

@Subz,

You've done it again. You nailed it:lol: WOW!!!:lmao::lmao:. I have nothing to say but your the best.B)... Thanks Subz!!


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

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

×