Jump to content

Help Unzipping multiple zip files to and contents to one folder


gp25
 Share

Recommended Posts

Hello all respectable AutoIT Guru's....

I got a ton of help on the last post and I really appreciated you guys pointing me in the right direction.

I am attempting to write a little program for a blind lady who downloads books from the braille institute. I need to make it easy for her to extract all of the downloaded books and put them into a folder well actually a cassette that she plugs in via USB.

The files all come down as .zips and will be placed in one folder. I need a program to go through and unzip all of the ".zips" and copy or place all of the contents into her cassette drive or usb drive.

I have been looking for like two weeks and I see alot on zipping or adding files to archives however I am having a ton of trouble trying to unzip. I have downloaded all of the UDFs and am still unable to do it. Please help me out in any way you can!

Thanks in advance,

GP

here is what I have not that it does anything...

#include <zip.au3>

_Zip_UnzipAll("C:\Users\gerrit.corporate\Desktop\adobecscleaner.zip", "C:\Users\gerrit.corporate\Desktop\Unzipped", 1)

Link to comment
Share on other sites

Hello all respectable AutoIT Guru's....

I got a ton of help on the last post and I really appreciated you guys pointing me in the right direction.

I am attempting to write a little program for a blind lady who downloads books from the braille institute. I need to make it easy for her to extract all of the downloaded books and put them into a folder well actually a cassette that she plugs in via USB.

The files all come down as .zips and will be placed in one folder. I need a program to go through and unzip all of the ".zips" and copy or place all of the contents into her cassette drive or usb drive.

I have been looking for like two weeks and I see alot on zipping or adding files to archives however I am having a ton of trouble trying to unzip. I have downloaded all of the UDFs and am still unable to do it. Please help me out in any way you can!

Thanks in advance,

GP

here is what I have not that it does anything...

#include <zip.au3>

_Zip_UnzipAll("C:Usersgerrit.corporateDesktopadobecscleaner.zip", "C:Usersgerrit.corporateDesktopUnzipped", 1)

COME ON GUYS!!! ITS FOR A BLIND LADY HELP A BROTHER OUT!
Link to comment
Share on other sites

#cs ----------------------------------------------------------------------------

AutoIt Version: 3.3.8.1

Author: myName

Script Function:

Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

_ExtractZip("C:Usersgpreston.corporatedesktopadobecscleaner.zip", "C:Usersgpreston.corporatedesktopunzipped")

; #FUNCTION# ;===============================================================================

;

; Name...........: _ExtractZip

; Description ...: Extracts file/folder from ZIP compressed file

; Syntax.........: _ExtractZip($sZipFile, $sDestinationFolder)

; Parameters ....: $sZipFile - full path to the ZIP file to process

; $sDestinationFolder - folder to extract to. Will be created if it does not exsist exist.

; Return values .: Success - Returns 1

; - Sets @error to 0

; Failure - Returns 0 sets @error:

; |1 - Shell Object creation failure

; |2 - Destination folder is unavailable

; |3 - Structure within ZIP file is wrong

; |4 - Specified file/folder to extract not existing

; Author ........: trancexx, modifyed by corgano

;

;==========================================================================================

Func _ExtractZip($sZipFile, $sDestinationFolder, $sFolderStructure = "")

Local $i

Do

$i += 1

$sTempZipFolder = @TempDir & "Temporary Directory " & $i & " for " & StringRegExpReplace($sZipFile, ".*", "")

Until Not FileExists($sTempZipFolder) ; this folder will be created during extraction

Local $oShell = ObjCreate("Shell.Application")

If Not IsObj($oShell) Then

Return SetError(1, 0, 0) ; highly unlikely but could happen

EndIf

Local $oDestinationFolder = $oShell.NameSpace($sDestinationFolder)

If Not IsObj($oDestinationFolder) Then

DirCreate($sDestinationFolder)

;~ Return SetError(2, 0, 0) ; unavailable destionation location

EndIf

Local $oOriginFolder = $oShell.NameSpace($sZipFile & "" & $sFolderStructure) ; FolderStructure is overstatement because of the available depth

If Not IsObj($oOriginFolder) Then

Return SetError(3, 0, 0) ; unavailable location

EndIf

Local $oOriginFile = $oOriginFolder.Items();get all items

If Not IsObj($oOriginFile) Then

Return SetError(4, 0, 0) ; no such file in ZIP file

EndIf

; copy content of origin to destination

$oDestinationFolder.CopyHere($oOriginFile, 20) ; 20 means 4 and 16, replaces files if asked

DirRemove($sTempZipFolder, 1) ; clean temp dir

Return 1 ; All OK!

EndFunc

Link to comment
Share on other sites

That should work, try checking the return code of the error macro.

Maybe there's something happening that doesn't let it work.

Could be a few things, like not having permissions for something.

#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.8.1
    Author:         myName

    Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

_ExtractZip("C:\test\gpreston.corporate\test.zip", "C:\test")
Switch @error
    Case 1
        MsgBox(16, "Error!", "Object creation failure D:")
    Case 2
        MsgBox(16, "Error!", "Cannot create directory for extracting!")
    Case 3
        MsgBox(16, "Error!",  "unavailable location!")
    Case 4
        MsgBox(16, "Error!", "No files were found in zip, or something else happened!")
    Case Else
        MsgBox(64, "Information", "Everything went ok, if files still did not end up where you wanted then maybe you do not have required permission to move files around, run as administrator.")
EndSwitch

; #FUNCTION# ;===============================================================================
;
; Name...........: _ExtractZip
; Description ...: Extracts file/folder from ZIP compressed file
; Syntax.........: _ExtractZip($sZipFile, $sDestinationFolder)
; Parameters ....: $sZipFile - full path to the ZIP file to process
;   $sDestinationFolder - folder to extract to. Will be created if it does not exsist exist.
; Return values .: Success - Returns 1
;   - Sets @error to 0
;   Failure - Returns 0 sets @error:
;   |1 - Shell Object creation failure
;   |2 - Destination folder is unavailable
;   |3 - Structure within ZIP file is wrong
;   |4 - Specified file/folder to extract not existing
; Author ........: trancexx, modifyed by corgano
;
;==========================================================================================
Func _ExtractZip($sZipFile, $sDestinationFolder, $sFolderStructure = "")

    Local $i
    Do
        $i += 1
        $sTempZipFolder = @TempDir & "\Temporary Directory " & $i & " for " & StringRegExpReplace($sZipFile, ".*\\", "")
    Until Not FileExists($sTempZipFolder) ; this folder will be created during extraction

    Local $oShell = ObjCreate("Shell.Application")

    If Not IsObj($oShell) Then
        Return SetError(1, 0, 0) ; highly unlikely but could happen
    EndIf

    Local $oDestinationFolder = $oShell.NameSpace($sDestinationFolder)
    If Not IsObj($oDestinationFolder) Then
        DirCreate($sDestinationFolder)
        If Not FileExists($sDestinationFolder) Then
            Return SetError(2, 0, 0) ; unavailable destionation location
        EndIf
    EndIf

    Local $oOriginFolder = $oShell.NameSpace($sZipFile & "\" & $sFolderStructure) ; FolderStructure is overstatement because of the available depth
    If Not IsObj($oOriginFolder) Then
        Return SetError(3, 0, 0) ; unavailable location
    EndIf

    Local $oOriginFile = $oOriginFolder.Items();get all items
    If Not IsObj($oOriginFile) Then
        Return SetError(4, 0, 0) ; no such file in ZIP file
    EndIf

    ; copy content of origin to destination
    Local $Success = $oDestinationFolder.CopyHere($oOriginFile, 20) ; 20 means 4 and 16, replaces files if asked
    DirRemove($sTempZipFolder, 1) ; clean temp dir

    Return 1 ; All OK!

EndFunc   ;==>_ExtractZip

If you want, you can post the complete script and tell me what it needs to do and maybe I can help you with it.

Edited by DeputyDerp
Link to comment
Share on other sites

That should work, try checking the return code of the error macro.

Maybe there's something happening that doesn't let it work.

Could be a few things, like not having permissions for something.

#cs ----------------------------------------------------------------------------

AutoIt Version: 3.3.8.1
Author: myName

Script Function:
Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

_ExtractZip("C:\test\gpreston.corporate\test.zip", "C:\test")
Switch @error
Case 1
MsgBox(16, "Error!", "Object creation failure D:")
Case 2
MsgBox(16, "Error!", "Cannot create directory for extracting!")
Case 3
MsgBox(16, "Error!", "unavailable location!")
Case 4
MsgBox(16, "Error!", "No files were found in zip, or something else happened!")
Case Else
MsgBox(64, "Information", "Everything went ok, if files still did not end up where you wanted then maybe you do not have required permission to move files around, run as administrator.")
EndSwitch

; #FUNCTION# ;===============================================================================
;
; Name...........: _ExtractZip
; Description ...: Extracts file/folder from ZIP compressed file
; Syntax.........: _ExtractZip($sZipFile, $sDestinationFolder)
; Parameters ....: $sZipFile - full path to the ZIP file to process
; $sDestinationFolder - folder to extract to. Will be created if it does not exsist exist.
; Return values .: Success - Returns 1
; - Sets @error to 0
; Failure - Returns 0 sets @error:
; |1 - Shell Object creation failure
; |2 - Destination folder is unavailable
; |3 - Structure within ZIP file is wrong
; |4 - Specified file/folder to extract not existing
; Author ........: trancexx, modifyed by corgano
;
;==========================================================================================
Func _ExtractZip($sZipFile, $sDestinationFolder, $sFolderStructure = "")

Local $i
Do
$i += 1
$sTempZipFolder = @TempDir & "\Temporary Directory " & $i & " for " & StringRegExpReplace($sZipFile, ".*\\", "")
Until Not FileExists($sTempZipFolder) ; this folder will be created during extraction

Local $oShell = ObjCreate("Shell.Application")

If Not IsObj($oShell) Then
Return SetError(1, 0, 0) ; highly unlikely but could happen
EndIf

Local $oDestinationFolder = $oShell.NameSpace($sDestinationFolder)
If Not IsObj($oDestinationFolder) Then
DirCreate($sDestinationFolder)
If Not FileExists($sDestinationFolder) Then
Return SetError(2, 0, 0) ; unavailable destionation location
EndIf
EndIf

Local $oOriginFolder = $oShell.NameSpace($sZipFile & "\" & $sFolderStructure) ; FolderStructure is overstatement because of the available depth
If Not IsObj($oOriginFolder) Then
Return SetError(3, 0, 0) ; unavailable location
EndIf

Local $oOriginFile = $oOriginFolder.Items();get all items
If Not IsObj($oOriginFile) Then
Return SetError(4, 0, 0) ; no such file in ZIP file
EndIf

; copy content of origin to destination
Local $Success = $oDestinationFolder.CopyHere($oOriginFile, 20) ; 20 means 4 and 16, replaces files if asked
DirRemove($sTempZipFolder, 1) ; clean temp dir

Return 1 ; All OK!

EndFunc ;==>_ExtractZip

If you want, you can post the complete script and tell me what it needs to do and maybe I can help you with it.

DeputyDert...that worked great...here is my issue or what i need to do....

This blind lady will download like lets say 7 or 8 virtual books which are .zip files all named differently such as DB-anderson123.zip

I need to have this program unzip each book in the folder and move all of the unzipped files to a desktop folder called "Anne's Books" which is really a usb cassette that she has plugged in. I was trying to do it with listtoarray but i really dont know much about this autoit stuff. Any...i mean any help would be greatly appreciated.

Thank you in advance again!!

GP :thumbsup:

Link to comment
Share on other sites

First of all, don't bump your post in less than 24 hours, second of all stop being rude when bumping your posts.

This is a volunteer effort on this forum, not everyone knows what it is you need, and bumping your post in just over an hour is ridiculous. Give it some time and perhaps someone with the answer will have a look at this. You do realize that some people like to sleep at night and have to work during the day?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Well, it would help out a lot if you posted a concept of what you want.

Try writing down what basically needs to be done in excruciating detail, and I'll try my best.

atm, I'm like balancing several things I'm doing, but I'll try and help your cause on my spare time :)

Link to comment
Share on other sites

What's wrong with the ZIP UDF by wraithdu?

UDF List:

 
_AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

@DeputyDerp

AutoIt Script to Unzip multiple .zips in a specific folder for example: this lady downloads books from the braille library and they get downloaded as .zips they contain multiple different file types and stuff that make up one virtual book. I need to extract each of the "books" or .zips from lets say "Downloaded Books" to a folder called "Anne's Books" thats all.

@Guiness I tried to use it however I was having trouble with the syntax. If you could help steer me in the right direction it would be greatly appreciated. I am trying to help this lady who is blind and I have been having a hard time.

DeputyDerp back to what it needs to do. I need it to go through the DOWNLOADED BOOKS folder and individually unzip each .zip and and copy all of the unzipped contents to a folder called Anne's Books which will be located on the desktop. The Downloaded Books folder will be located on the Desktop as well.

Please email me at gpreston@luminance.us.com if you have any questions or need any additional info.

Thanks in advance,

Link to comment
Share on other sites

Get a list of .zip files using _FileListToArray() and then loop through the list calling your _ExtractZip() function each time.

Considering her handicap, she might find audible cues helpful...

#include <File.au3>
Global $sSrcPath = @MyDocumentsDir & "\Downloaded Files"
Global $sDestPath = @DesktopDir & "\Anne's Books"

;===========================================================
Global $aZip = _FileListToArray($sSrcPath, "*.zip", 1) ; get array of .zip files in source dir

If Not @error Then ; zips found
    For $x = 1 to $aZip[0]
        Beep (800,100) ; happy beep = zip found
        _ExtractZip($sSrcPath & "\" & $aZip[$x])
   Next
Else
    Beep(490,500) ; bummer beep = no zips found
EndIf

;===========================================================
Func _ExtractZip($path)
     ; unzip each $path to $sDestPath here
EndFunc
Edited by Spiff59
Link to comment
Share on other sites

Well, I guess you could do it something like this. Maybe you can work up from there?

But I'm curious, how do you plan the script be run and told it needs to download what specific zip files.

I'm getting confused because the way you explain it, you make it sound simple, when it shouldn't.

#include <array.au3>
#include <File.au3>

#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.8.1
    Author:         myName

    Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------


Global $TempFolder
OnAutoItExitRegister("_Exit")

_Download_EBook("http://someplace.com/zip.zip", @DesktopDir & "\Anne's Books")

Func _Download_EBook($ZipURL, $Destination); $ZipURL = website link to the zip, $Destination = Place where extracted files will go

    If StringRight($Destination, 1) == "\" Then $Destination = StringTrimRight($Destination, 1)

    $TempFolder = _TempFile(@TempDir, "~", "")
    Local $TempZip = _TempFile($TempFolder, "~", ".zip")

    If Not InetGet($ZipURL, $TempZip, 9) Then
        MsgBox(16, "Error!", "The zip file from the internet location provided could not be reached!")
        Return SetError(1, 0, False)
    EndIf

    _ExtractZip($TempZip, FileGetShortName($TempFolder))
    If @error Then SetError(3, @error, False)

    FileDelete($TempZip)

    Local $FilesDownloaded = _FileListToArray($TempFolder)

    ;_ArrayDisplay($FilesDownloaded); just show what files were found

    For $I = 1 To $FilesDownloaded[0]

        FileMove($TempFolder & "\" & $FilesDownloaded[$I], _UniqueName($Destination & "\" & $FilesDownloaded[$I]), 9); move the file to destination, if file exists already, rename it to "file (1).txt" etc

    Next

    Return SetError(0, 0, True)

EndFunc

Func _UniqueName($FilePath)
    If FileExists($FilePath) Then
        Local $Split = StringSplit($FilePath, "\")
        $FileName = $Split[$Split[0]]

        Local $Path
        For $I = 1 To $Split[0] - 1
            $Path &= $Split[$I] & "\"
        Next

        If StringInStr($FileName, ".", 2) Then
            $FileName = StringReplace($FileName, ".", " (%s)." , -1);If you have a file like "C:\test\name.with.many.dots.txt", it will be renamed to "C:\test\name.with.many.dots (1).txt" if the file existed..
            Local $TempName
            For $I = 1 To 10e+100
                $TempName = StringFormat($FileName, $I)
                If Not FileExists($Path & $TempName) Then ExitLoop
            Next
            $FilePath = $Path & $TempName
        Else
            $FileName &= " (%s)"
            Local $TempName
            For $I = 1 To 10e+100
                $TempName = StringFormat($FileName, $I)
                If Not FileExists($Path & $TempName) Then ExitLoop
            Next
            $FilePath = $Path & $TempName
        EndIf
    EndIf
    Return $FilePath
EndFunc


Func _Exit()
    If FileExists($TempFolder) Then FileDelete($TempFolder)
EndFunc

; #FUNCTION# ;===============================================================================
;
; Name...........: _ExtractZip
; Description ...: Extracts file/folder from ZIP compressed file
; Syntax.........: _ExtractZip($sZipFile, $sDestinationFolder)
; Parameters ....: $sZipFile - full path to the ZIP file to process
;   $sDestinationFolder - folder to extract to. Will be created if it does not exsist exist.
; Return values .: Success - Returns 1
;   - Sets @error to 0
;   Failure - Returns 0 sets @error:
;   |1 - Shell Object creation failure
;   |2 - Destination folder is unavailable
;   |3 - Structure within ZIP file is wrong
;   |4 - Specified file/folder to extract not existing
; Author ........: trancexx, modifyed by corgano
;
;==========================================================================================
Func _ExtractZip($sZipFile, $sDestinationFolder, $sFolderStructure = "")

    Local $i
    Do
        $i += 1
        $sTempZipFolder = @TempDir & "\Temporary Directory " & $i & " for " & StringRegExpReplace($sZipFile, ".*\\", "")
    Until Not FileExists($sTempZipFolder) ; this folder will be created during extraction

    Local $oShell = ObjCreate("Shell.Application")

    If Not IsObj($oShell) Then
        Return SetError(1, 0, 0) ; highly unlikely but could happen
    EndIf

    Local $oDestinationFolder = $oShell.NameSpace($sDestinationFolder)
    If Not IsObj($oDestinationFolder) Then
        DirCreate($sDestinationFolder)
        If Not FileExists($sDestinationFolder) Then
            Return SetError(2, 0, 0) ; unavailable destionation location
        EndIf
    EndIf

    Local $oOriginFolder = $oShell.NameSpace($sZipFile & "\" & $sFolderStructure) ; FolderStructure is overstatement because of the available depth
    If Not IsObj($oOriginFolder) Then
        Return SetError(3, 0, 0) ; unavailable location
    EndIf

    Local $oOriginFile = $oOriginFolder.Items();get all items
    If Not IsObj($oOriginFile) Then
        Return SetError(4, 0, 0) ; no such file in ZIP file
    EndIf

    ; copy content of origin to destination
    Local $Success = $oDestinationFolder.CopyHere($oOriginFile, 20) ; 20 means 4 and 16, replaces files if asked
    DirRemove($sTempZipFolder, 1) ; clean temp dir

    Return 1 ; All OK!

EndFunc   ;==>_ExtractZip
Link to comment
Share on other sites

@Spifff59

_

I tried to run your script with the correct location of the files however nothing happened.

@DeputyDerp

She has the files downloaded already. I taught her to go online and scan through the braille library books then download them to a location on the desktop called "Downloaded Books" She is able to kick off the "Unzipper Program" that I am writing so basically all it needs to do is Go through the "Downloaded Books" folder and extract each of the .zip's to a specific location such as "Anne's Books" There will be like 8 to 10 books which are made up of a bunch of different file types and all placed in different .zips. So i need the program to simply extract all of the .zips(Books) from "Downloaded Books" to the "Anne's Books" folder. Thats it really. Just to extract multiple zip files to one folder location and overwrite any existing files if there happens to be any becuase sometimes each of the books has one or two files that are the same and she is unable to use the mouse or click yes to the prompts.

Thank you guys so much for your help. I feel like we are close....as they say close but no cigar...thanks again for your help @DeputyDerp...sorry for not making it clear that we already have the downloads on the Desktop in a folder called "Downloaded Books"

:)

I am so excited to get this to actually work for her it will make her life sooooo much easier and I will make it a point to give any positive reviews and what have you where applicable.

I will be on tomorrow also all day while at work...and if you can or need to just email me at (gpreston@luminance.us.com) or even call me if it makes it any easier for you guys to help me...my number is (323) 383-3683 In cali.

Link to comment
Share on other sites

@Spifff59_

I tried to run your script with the correct location of the files however nothing happened.

Something happened. It either beeped (if the PC has a speaker), or it crashed.

I'd left the _ExtractZip() function empty to allow you to choose which of the versions here to plug in.

Here's the same demo with different parms and some eye-candy, but it still doesn't do everything that you want to happen.

You still need to plug-in whatever basic extract function it is that you prefer.

#include <File.au3>
Global $sSrcPath = @DesktopDir & "\Downloaded Files"
Global $sDestPath = @DesktopDir & "\Anne's Books"

;===========================================================
Global $aZip = _FileListToArray($sSrcPath, "*.zip", 1) ; get array of .zip files in source dir
If @error Then
    Beep(490,500) ; bummer beep = no zips found
Else
    For $x = 1 to $aZip[0]
        Beep (800,100) ; happy beep = zip found
        _ExtractZip($sSrcPath & "\" & $aZip[$x], $sDestPath)
    Next
EndIf

;===========================================================
Func _ExtractZip($sZipIn, $sZipOut, $sOptions = "")
    ToolTip("SRC:   " & $sZipIn & @CRLF &  "DEST: " & $sZipOut, @DesktopWidth / 2, @DesktopHeight / 2, "Extracting eBook.  Please wait...", 1, 2)
    Sleep(2500)
EndFunc
Link to comment
Share on other sites

Maybe more like this?

#include <File.au3>

#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.8.1
    Author:         myName

    Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

;_Setup_ebooks("C:\user\Downloaded ebooks\", @DesktopDir & "\Anne's Books")

Func _Setup_ebooks($Source, $Destination)

    If StringRight($Destination, 1) == "\" Then $Destination = StringTrimRight($Destination, 1)
    If StringRight($Source, 1) == "\" Then $Source = StringTrimRight($Source, 1)

    Local $FilesFound = _FileListToArray($Source)
    Local $TempDestination
    Local $TempName
    Local $StrSpl

    For $I = 1 To $FilesFound[0]
        $TempDestination = $Destination & "\" & $FilesFound[$I]
        If StringInStr($FilesFound[$I], ".", 2) Then
            $StrSpl = StringSplit($FilesFound[$I], ".")
            For $I = 1 To $StrSpl[0] - 1
                If $I > 1 Then $TempName &= "."
                $TempName &= $StrSpl[$I]
            Next
            $TempDestination = $Destination & "\" & $TempName
        EndIf
        $TempDestination = _UniqueName($TempDestination)
        _ExtractZip($Source & "\" & $FilesFound[$I], $TempDestination)
    Next

    Return SetError(0, 0, True)

EndFunc

Func _UniqueName($FilePath)
    If FileExists($FilePath) Then
        Local $Split = StringSplit($FilePath, "\")
        $FileName = $Split[$Split[0]]

        Local $Path
        For $I = 1 To $Split[0] - 1
            $Path &= $Split[$I] & "\"
        Next

        If StringInStr($FileName, ".", 2) Then
            $FileName = StringReplace($FileName, ".", " (%s)." , -1);If you have a file like "C:testname.with.many.dots.txt", it will be renamed to "C:testname.with.many.dots(1).txt" if the file existed..
            Local $TempName
            For $I = 1 To 10e+100
                $TempName = StringFormat($FileName, $I)
                If Not FileExists($Path & $TempName) Then ExitLoop
            Next
            $FilePath = $Path & $TempName
        Else
            $FileName &= " (%s)"
            Local $TempName
            For $I = 1 To 10e+100
                $TempName = StringFormat($FileName, $I)
                If Not FileExists($Path & $TempName) Then ExitLoop
            Next
            $FilePath = $Path & $TempName
        EndIf
    EndIf
    Return $FilePath
EndFunc


; #FUNCTION# ;===============================================================================
;
; Name...........: _ExtractZip
; Description ...: Extracts file/folder from ZIP compressed file
; Syntax.........: _ExtractZip($sZipFile, $sDestinationFolder)
; Parameters ....: $sZipFile - full path to the ZIP file to process
;   $sDestinationFolder - folder to extract to. Will be created if it does not exsist exist.
; Return values .: Success - Returns 1
;   - Sets @error to 0
;   Failure - Returns 0 sets @error:
;   |1 - Shell Object creation failure
;   |2 - Destination folder is unavailable
;   |3 - Structure within ZIP file is wrong
;   |4 - Specified file/folder to extract not existing
; Author ........: trancexx, modifyed by corgano
;
;==========================================================================================
Func _ExtractZip($sZipFile, $sDestinationFolder, $sFolderStructure = "")

    Local $i
    Do
        $i += 1
        $sTempZipFolder = @TempDir & "\Temporary Directory " & $i & " for " & StringRegExpReplace($sZipFile, ".*\\", "")
    Until Not FileExists($sTempZipFolder) ; this folder will be created during extraction

    Local $oShell = ObjCreate("Shell.Application")

    If Not IsObj($oShell) Then
        Return SetError(1, 0, 0) ; highly unlikely but could happen
    EndIf

    Local $oDestinationFolder = $oShell.NameSpace($sDestinationFolder)
    If Not IsObj($oDestinationFolder) Then
        DirCreate($sDestinationFolder)
        If Not FileExists($sDestinationFolder) Then
            Return SetError(2, 0, 0) ; unavailable destionation location
        EndIf
    EndIf

    Local $oOriginFolder = $oShell.NameSpace($sZipFile & "\" & $sFolderStructure) ; FolderStructure is overstatement because of the available depth
    If Not IsObj($oOriginFolder) Then
        Return SetError(3, 0, 0) ; unavailable location
    EndIf

    Local $oOriginFile = $oOriginFolder.Items();get all items
    If Not IsObj($oOriginFile) Then
        Return SetError(4, 0, 0) ; no such file in ZIP file
    EndIf

    ; copy content of origin to destination
    Local $Success = $oDestinationFolder.CopyHere($oOriginFile, 20) ; 20 means 4 and 16, replaces files if asked
    DirRemove($sTempZipFolder, 1) ; clean temp dir

    Return 1 ; All OK!

EndFunc   ;==>_ExtractZip
Edited by DeputyDerp
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...