KickStarter15 Posted July 6, 2018 Share Posted July 6, 2018 (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\": - Sub-folders found from the first folder "abc12345": Here's my code: expandcollapse popup#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 July 6, 2018 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. Link to comment Share on other sites More sharing options...
Subz Posted July 6, 2018 Share Posted July 6, 2018 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 expandcollapse popup#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 Link to comment Share on other sites More sharing options...
KickStarter15 Posted July 7, 2018 Author Share Posted July 7, 2018 @Subz, Thanks, but I don't get yet the complexity of your code (maybe later ) 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, 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. Link to comment Share on other sites More sharing options...
Subz Posted July 7, 2018 Share Posted July 7, 2018 "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. Link to comment Share on other sites More sharing options...
KickStarter15 Posted July 7, 2018 Author Share Posted July 7, 2018 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. 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. 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. Link to comment Share on other sites More sharing options...
Subz Posted July 8, 2018 Share Posted July 8, 2018 So can you tell us what the code I posted above is missing, in terms of removing duplicate sized folders, without removing the exceptions? Link to comment Share on other sites More sharing options...
KickStarter15 Posted July 9, 2018 Author Share Posted July 9, 2018 (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. 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. 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. 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. Edited July 9, 2018 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. Link to comment Share on other sites More sharing options...
KickStarter15 Posted July 9, 2018 Author Share Posted July 9, 2018 (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 July 9, 2018 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. Link to comment Share on other sites More sharing options...
Subz Posted July 9, 2018 Share Posted July 9, 2018 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 Link to comment Share on other sites More sharing options...
KickStarter15 Posted July 9, 2018 Author Share Posted July 9, 2018 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: 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. Link to comment Share on other sites More sharing options...
Subz Posted July 9, 2018 Share Posted July 9, 2018 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? Link to comment Share on other sites More sharing options...
KickStarter15 Posted July 10, 2018 Author Share Posted July 10, 2018 @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. 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. Link to comment Share on other sites More sharing options...
Subz Posted July 11, 2018 Share Posted July 11, 2018 Sorry have a big project on at the moment, only got the following so far: expandcollapse popup#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 KickStarter15 1 Link to comment Share on other sites More sharing options...
KickStarter15 Posted July 11, 2018 Author Share Posted July 11, 2018 @Subz, Thanks, man and no worries... However, I can't make it work due to below log generated. This is the format of my .ini file (as you suggested): Could not trace the cause of error 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. Link to comment Share on other sites More sharing options...
Subz Posted July 11, 2018 Share Posted July 11, 2018 Sorry forgot to post the ini, I thought I'd match it to your radio buttons. expandcollapse popup[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= KickStarter15 1 Link to comment Share on other sites More sharing options...
KickStarter15 Posted July 12, 2018 Author Share Posted July 12, 2018 @Subz, You've done it again. You nailed it WOW!!!. I have nothing to say but your the best.... 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now