KickStarter15 Posted February 6, 2020 Posted February 6, 2020 (edited) Hi Experts, Hope everyone are having a good day! I have this question so far, is it possible for AutoIt language can zip a multiple folders from the path given? like the below folders. Before: After and expected: I tried checking the net but only single folder zipping. Maybe someone here can point me to the right direction. Thanks in advance Experts.... KS15 Edited February 7, 2020 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.
Musashi Posted February 6, 2020 Posted February 6, 2020 On 2/6/2020 at 7:14 AM, KickStarter15 said: Maybe someone here can point me to the right direction. Expand Would the following be an acceptable solution for you? You read the folders into an array using _FileListToArrayRec (flag = $FLTAR_FOLDERS). Then loop through the array and pack each folder with the command line variant of 7-Zip (place 7z.dll and 7za.exe i.e. in the @ScriptDir). "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
KickStarter15 Posted February 6, 2020 Author Posted February 6, 2020 On 2/6/2020 at 7:33 AM, Musashi said: (place 7z.dll and 7za.exe i.e. in the @ScriptDir). Expand Thanks, that can be done. On 2/6/2020 at 7:33 AM, Musashi said: pack each folder with the command line variant of 7-Zip Expand Is there a package 7-zip on this that is needed? 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.
Musashi Posted February 6, 2020 Posted February 6, 2020 (edited) On 2/6/2020 at 8:00 AM, KickStarter15 said: Is there a package 7-zip on this that is needed? Expand You will find the components 7z.dll and 7za.exe if you install 7-Zip. Edited May 24, 2021 by Musashi Attachment removed "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
Musashi Posted February 6, 2020 Posted February 6, 2020 (edited) Here an example script : #include <File.au3> #include <StringConstants.au3> #include <Array.au3> Global $g_sBaseDir, $g_aFolders, $g_sCommand $g_sBaseDir = @ScriptDir $g_aFolders = _FileListToArray($g_sBaseDir, "*", $FLTAR_FOLDERS) If @error Then ConsoleWrite("! @@ Error : _FileListToArray" & @CRLF) Exit EndIf _ArrayDisplay($g_aFolders, "Folders") ; *** just for display For $i = 1 To $g_aFolders[0] ; only folders with 10 digits are valid : If StringRegExp($g_aFolders[$i], "^\d{10}$", $STR_REGEXPMATCH) Then ConsoleWrite("> >>>> Foldername match = " & $g_aFolders[$i] & @CRLF) ; Variant 1 : without Progresswindow ;$g_sCommand = @ScriptDir & '\7za.exe a -y -tzip "' & $g_aFolders[$i] & '" "' & $g_aFolders[$i] & '"' ;RunWait ($g_sCommand, "", @SW_HIDE) ; Variant 2 : with Progresswindow $g_sCommand = @ScriptDir & '\7zG.exe a -y -tzip "' & $g_aFolders[$i] & '" "' & $g_aFolders[$i] & '"' RunWait ($g_sCommand, "", @SW_SHOW) EndIf Next EDIT : @KickStarter15 Besides 7za.exe, 7-Zip offers another standalone variation (7zG.exe) with a progress bar. This can be useful if the folders contain large amounts of data. I have enhanced the example above and also added the 7zG.exe as a zipfile (see attachment). 7zG.zipFetching info... Edited February 6, 2020 by Musashi Enhancement argumentum 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
KickStarter15 Posted February 6, 2020 Author Posted February 6, 2020 @Musashi Thanks it is working. However, the folder is not just 10 digits or how many letters, it vary on the folder being stored on that certain path. So how can I change this peace of RegEx "^\d{10}$" here. Some Folders has folder name of ABC1234 or ABCD11 means letters and numbers. 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.
Musashi Posted February 6, 2020 Posted February 6, 2020 On 2/6/2020 at 9:25 AM, KickStarter15 said: However, the folder is not just 10 digits Expand Is there any pattern by which the folders can be identified? Otherwise all folders of the base directory would be taken. Alternatively you could create an array with the desired folders, e.g. as .csv , or in the script itself. "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
KickStarter15 Posted February 6, 2020 Author Posted February 6, 2020 @Musashi I think i got it, I change this RegEx "^\d{10}$" to this "^." means anything. Is this correct? 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.
Musashi Posted February 6, 2020 Posted February 6, 2020 On 2/6/2020 at 9:37 AM, KickStarter15 said: I think i got it, I change this RegEx "^\d{10}$" to this "^." means anything. Is this correct? Expand If you want to pack all folders, then you can completely skip If StringRegExp . #include <File.au3> #include <StringConstants.au3> #include <Array.au3> Global $g_sBaseDir, $g_aFolders, $g_sCommand $g_sBaseDir = @ScriptDir $g_aFolders = _FileListToArray($g_sBaseDir, "*", $FLTAR_FOLDERS) If @error Then ConsoleWrite("! @@ Error : _FileListToArray" & @CRLF) Exit EndIf _ArrayDisplay($g_aFolders, "Folders") ; *** just for display For $i = 1 To $g_aFolders[0] ConsoleWrite("> >>>> Foldername = " & $g_aFolders[$i] & @CRLF) ; Variant 1 : without Progresswindow ;$g_sCommand = @ScriptDir & '\7za.exe a -y -tzip "' & $g_aFolders[$i] & '" "' & $g_aFolders[$i] & '"' ;RunWait ($g_sCommand, "", @SW_HIDE) ; Variant 2 : with Progresswindow $g_sCommand = @ScriptDir & '\7zG.exe a -y -tzip "' & $g_aFolders[$i] & '" "' & $g_aFolders[$i] & '"' RunWait ($g_sCommand, "", @SW_SHOW) Next KickStarter15 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
Nine Posted February 6, 2020 Posted February 6, 2020 If someone doesn't want to use external program, this could be an alternative : expandcollapse popup#include <Constants.au3> #include <String.au3> #include <Array.au3> #include <File.au3> Opt("MustDeclareVars", 1) Const $g_sBaseDir = "C:\Apps\Temp" Local $g_aFolders = _FileListToArray($g_sBaseDir, "*", $FLTAR_FOLDERS, True) If @error Then Exit ConsoleWrite("! @@ Error : _FileListToArray" & @CRLF) _ArrayDisplay($g_aFolders, "Folders") ; *** just for display For $i = 1 To $g_aFolders[0] ConsoleWrite("> >>>> Foldername = " & $g_aFolders[$i] & @CRLF) Zip($g_aFolders[$i] & ".zip", $g_aFolders[$i]) Next Func Zip($sZipFile, $sSourceFolder) If FileExists($sZipFile) Then Return SetError(1) ; destination file already exists If Not FileExists($sSourceFolder) Then Return SetError(2) ; source does not exist Local $hFile = FileOpen($sZipFile, $FO_CREATEPATH + $FO_OVERWRITE + $FO_BINARY) Local Const $sString = Chr(80) & Chr(75) & Chr(5) & Chr(6) & _StringRepeat(Chr(0), 18) FileWrite($hFile, $sString) FileClose($hFile) Local $oShell = ObjCreate("shell.application") If Not $oShell.NameSpace($sSourceFolder).items.count Then Return SetError(3) ; folder empty Local $iFiles = 0 For $oFile In $oShell.NameSpace($sSourceFolder).items $oShell.NameSpace($sZipFile).copyhere($oFile) Do Sleep(100) Until $oShell.NameSpace($sZipFile).items.count > $iFiles $iFiles = $oShell.NameSpace($sZipFile).items.count Next EndFunc ;==>Zip KickStarter15 1 “They did not know it was impossible, so they did it” ― Mark Twain Reveal hidden contents Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy
KickStarter15 Posted February 7, 2020 Author Posted February 7, 2020 @Musashi, Thank you so much, that gives my day a head start.😊 Thanks as well @Nine, it's working. 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.
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