Sekhar Posted April 3, 2014 Posted April 3, 2014 Hello, I need help in creating a script that enables me to the following automatically. I have a ZIp file by name abc.zip and it contains files-test.txt,dec.drl,tes.txt .What i need is that first it needs to unzip the file and then rename file names to parent zip file like abc.txt,abc.drl,abc.txt. and then finally it need to zip it back. Any inputs are highly appreciated. Thanks in advance. Best Regards, Sekhar
Moderators Melba23 Posted April 3, 2014 Moderators Posted April 3, 2014 Sekhar,Welcome to the AutoIt forum. But please pay attention to where you post - the "Examples" section where you started this thread is clearly marked: "This is NOT a general support forum!". I have moved the thread for you, but would ask you to be more careful in future. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Sekhar Posted April 3, 2014 Author Posted April 3, 2014 Sorry for the inconvinience.Thanks i will remeber this.
ZombieKillz Posted April 3, 2014 Posted April 3, 2014 Hi Sekhar, Since I had something similar to what you're asking, here you go. I have run a quick test and it seems to work okay using your example. It may be crude but works! I don't think you can have more than one file with the same name in a zip file, so I will leave that alone. abc.txt,abc.drl,abc.txt You will need the _Zip.au3 UDF created by wraithdu here --> expandcollapse popup#include <File.au3> #include <Array.au3> #include <_Zip.au3> _ZipRenameToParent() Func _ZipRenameToParent() Local $sPath = "C:\Temp\" ; sets up your path with trailing backslash for use later Local $zipfileList = _FileListToArray("C:\Temp", "abc.zip", 1) ; If more than one .zip file, change abc.zip to *.zip ; error checking for _FileListToArray If @error = 1 Then MsgBox(0, "", "No Folder Found.") Exit EndIf If @error = 4 Then MsgBox(0, "", "No File(s) Found.") Exit EndIf ; loops through files found from _FileListToArray -- one if you specify a particular filename, or multiple if you use *.zip above For $i = 1 to $zipfileList[0] $filename = StringTrimRight($zipfileList[$i], 4) $zipFile = _Zip_ListAll($sPath&$filename&".zip", 0) _Zip_Create($sPath&$filename&"_new.zip") ; create a new zip file to store renamed files into For $iZipfiles = 1 to UBound($zipFile) - 1 _Zip_Unzip($sPath&$filename&".zip", $zipFile[$iZipfiles], $sPath) $filetorename = $zipFile[$iZipfiles] $fileextension = StringRight($zipFile[$iZipfiles],4) FileMove($sPath&$filetorename, $sPath&$filename&$fileextension) _Zip_AddItem($sPath&$filename&"_new.zip", $sPath&$filename&$fileextension) FileDelete($sPath&$filename&$fileextension) Next FileDelete($sPath&$filename&".zip") ; deletes the original zip file FileMove($sPath&$filename&"_new.zip", $sPath&$filename&".zip") ; renames the _new.zip file to the original filename.zip Next MsgBox(0,"Done", "Finished renaming files within zip(s)") ; added for sanity purposes :-) EndFunc
Sekhar Posted April 4, 2014 Author Posted April 4, 2014 Hello , Thanks for your reply. I tried and what is happening is that i get message that done renaming but in the zip file no files are available.all are getting deleted. Do you have any inputs to resolve this > Thanks in advance.
Moderators Melba23 Posted April 7, 2014 Moderators Posted April 7, 2014 Sekhar,Your original requirement has a serious problem - renaming to "abc.txt, abc.drl, abc.txt" will not work as there are 2 files of the same name when renamed. If you assume that all the extensions are different (I used "test.txt, test.drl, test.au3"), then this script works perfectly for me:#include <Array.au3> #include <File.au3> #include "_Zip.au3" ; Declare paths $sName = "abc" $sOrgZip = @ScriptDir & "\" & $sName & ".zip" $sNewZip = @ScriptDir & "\Renamed.zip" $sUnzipped = @ScriptDir & "\Unzipped" $sRenamed = @ScriptDir & "\Renamed" ; Create folders DirCreate($sUnzipped) DirCreate($sRenamed) ; Unzip current file _Zip_UnzipAll($sOrgZip, $sUnzipped) ; Display results $aUnzipped = _FileListToArray($sUnzipped, "*.*", 1) _ArrayDisplay($aUnzipped, "Unzipped", Default, 8) ; Rename files and move to new folder For $i = 1 To $aUnzipped[0] FileMove($sUnzipped & "\" & $aUnzipped[$i], $sRenamed & "\" & $sName & StringRegExpReplace($aUnzipped[$i], "^.*\.", ".$1")) Next ; Display result $aRenamed = _FileListToArray($sRenamed, "*.*", 1) _ArrayDisplay($aRenamed, "Renamed", Default, 8) ; Create new zip file $sNewFile = _Zip_Create($sNewZip) ; Add renamed files For $i = 1 To $aRenamed[0] _Zip_AddItem($sNewFile, $sRenamed & "\" & $aRenamed[$i]) NextI leave it to you to check the zip content, delete the original zip and the 2 folders, and finally rename the new zip. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Sekhar Posted April 7, 2014 Author Posted April 7, 2014 Hello,Thanks. Now i have zip with only files with unique name.But when i run i get an error message that it say Subscript used with non Array Variable.? Any help?
Moderators Melba23 Posted April 7, 2014 Moderators Posted April 7, 2014 Sekhar,You need to add some errorchecking code to see where the error lies. Do you see both of the ArrayDisplay dialogs showing the unzipped and renamed files when you run the code? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
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