I want to extract all zipped files within a directory, and have the file/subfolder/folder/directory structure preserved in Windows Explorer.
Shadowpheonix wrote a script which is pretty close: viewtopic.php?f=76&t=9240&p=461352#p461352 . But it seems to delete the actual zipped folder name, as I explain here: viewtopic.php?p=461352#p461352
Any ideas?
How to Extract all Zipped Files In a Directory While Preserving Folder Structure
- flyingDman
- Posts: 2832
- Joined: 29 Sep 2013, 19:01
Re: How to Extract all Zipped Files In a Directory While Preserving Folder Structure
The native unz() function preserves the folder structure and does not delete the zip file.
example:
originally posted here: https://www.autohotkey.com/board/topic/60706-native-zip-and-unzip-xpvista7-ahk-l/
Code: Select all
Unz(sZip, sUnz) ; zip file, folder to unzip to
{
FileCreateDir, %sUnz%
psh := ComObjCreate("Shell.Application")
psh.Namespace( sUnz ).CopyHere( psh.Namespace( sZip ).items, 4|16 )
}
Code: Select all
zipfile := "C:\Users\" A_UserName "\Scripts\zip_test.zip"
unz(zipfile,A_Temp)
return
14.3 & 1.3.7
Re: How to Extract all Zipped Files In a Directory While Preserving Folder Structure
flyingDman, that looks great!
I assume I have to create a loop function to go through all of the files in the directory? If so, would the script be something like this:
??
I assume I have to create a loop function to go through all of the files in the directory? If so, would the script be something like this:
Code: Select all
zipfile := c:\users\REST OF PATH OF THE DIRECTORY
loop, Files, zipfile, FDR
Unz(zipfile,A_Temp)
return
- flyingDman
- Posts: 2832
- Joined: 29 Sep 2013, 19:01
Re: How to Extract all Zipped Files In a Directory While Preserving Folder Structure
Something like this:
Code: Select all
zipfolder := "C:\Users\" A_UserName "\Scripts" ; path of folder containing the zip files
dstntnfldr := A_temp ; path of the destination folder
loop, files, %zipfolder%\*.zip, FR
Unz(A_LoopFileFullPath, dstntnfldr)
14.3 & 1.3.7
Re: How to Extract all Zipped Files In a Directory While Preserving Folder Structure
Hmmm, I think I'm doing something wrong. Nothing gets created to my dstntnfldr ...flyingDman wrote: ↑09 May 2022, 20:40Something like this:Code: Select all
zipfolder := "C:\Users\" A_UserName "\Scripts" ; path of folder containing the zip files dstntnfldr := A_temp ; path of the destination folder loop, files, %zipfolder%\*.zip, FR Unz(A_LoopFileFullPath, dstntnfldr)
Re: How to Extract all Zipped Files In a Directory While Preserving Folder Structure
Are you looking in the correct temp directory?
C:\Users\<UserName>\AppData\Local\Temp
You can add MsgBox % A_temp to your script and it will display your temp location.
C:\Users\<UserName>\AppData\Local\Temp
You can add MsgBox % A_temp to your script and it will display your temp location.
Re: How to Extract all Zipped Files In a Directory While Preserving Folder Structure
run as admin?
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
- flyingDman
- Posts: 2832
- Joined: 29 Sep 2013, 19:01
Re: How to Extract all Zipped Files In a Directory While Preserving Folder Structure
I am using this function on a very regular basis to unzip downloads from sharepoint. I do not need admin privileges to do that.
14.3 & 1.3.7
Re: How to Extract all Zipped Files In a Directory While Preserving Folder Structure
I think my problem is either:
(1) I'm not sure how to use/access the temp folder; or
(2) I haven't added code to the script to be usable.
Specifically,confirms the correct temp folder. But when I run the script, the temp folder solely shows recent files with 0 bytes.
This doesn't seem helpful. What am I doing wrong?
Or do I need to add some code, and flyingDman is just giving me one portion of the code I need?
(1) I'm not sure how to use/access the temp folder; or
(2) I haven't added code to the script to be usable.
Specifically,
Code: Select all
MsgBox % A_temp
This doesn't seem helpful. What am I doing wrong?
Or do I need to add some code, and flyingDman is just giving me one portion of the code I need?
- flyingDman
- Posts: 2832
- Joined: 29 Sep 2013, 19:01
Re: How to Extract all Zipped Files In a Directory While Preserving Folder Structure
This is the only code you'll need:
Code: Select all
zipfile := "C:\Users\" A_UserName "\Scripts\zip_test.zip" ; change to your needs
unz(zipfile,A_Temp) ; can be another folder, change to your needs
return
Unz(sZip, sUnz) ; zip file, folder to unzip to
{
FileCreateDir, %sUnz%
psh := ComObjCreate("Shell.Application")
psh.Namespace( sUnz ).CopyHere( psh.Namespace( sZip ).items, 4|16 )
}
return
14.3 & 1.3.7
- JoeWinograd
- Posts: 2209
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: How to Extract all Zipped Files In a Directory While Preserving Folder Structure
Tested here...the native Unz() function worked perfectly!flyingDman wrote:This is the only code you'll need
Question for @flyingDman: Is there a comparable native Zip() function? Thanks, Joe
- flyingDman
- Posts: 2832
- Joined: 29 Sep 2013, 19:01
Re: How to Extract all Zipped Files In a Directory While Preserving Folder Structure
Yes. See here: https://www.autohotkey.com/board/topic/60706-native-zip-and-unzip-xpvista7-ahk-l/
I have less experience with the zipping function
I have less experience with the zipping function
14.3 & 1.3.7
- JoeWinograd
- Posts: 2209
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: How to Extract all Zipped Files In a Directory While Preserving Folder Structure
FYI, FileCopyDir supports a zip file as the source "directory" in v1.1.34.
I figured since the shell objects can be used to extract a zip, surely the shell function FileCopyDir uses can too. I was right, but FileCopyDir was checking if the source is a directory before attempting the copy.
Unfortunately it really can't work the other way (copying into a zip).
I figured since the shell objects can be used to extract a zip, surely the shell function FileCopyDir uses can too. I was right, but FileCopyDir was checking if the source is a directory before attempting the copy.
Unfortunately it really can't work the other way (copying into a zip).
Re: How to Extract all Zipped Files In a Directory While Preserving Folder Structure
It seems like this is a situation where I have a weird setting on my computer which is preventing the script from working. Still nothing but just a couple of 0 byte files in temp files.
- flyingDman
- Posts: 2832
- Joined: 29 Sep 2013, 19:01
Re: How to Extract all Zipped Files In a Directory While Preserving Folder Structure
@Lexicos Thank you for pointing this out. I should check the change log more often ...
14.3 & 1.3.7
- JoeWinograd
- Posts: 2209
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: How to Extract all Zipped Files In a Directory While Preserving Folder Structure
Didn't know that...nice!lexikos wrote:FYI, FileCopyDir supports a zip file as the source "directory" in v1.1.34.
Re: How to Extract all Zipped Files In a Directory While Preserving Folder Structure
Could my software version be the source of it not working for me? I'm using AHK 1.1.33.10 and Windows 10.
- flyingDman
- Posts: 2832
- Joined: 29 Sep 2013, 19:01
Re: How to Extract all Zipped Files In a Directory While Preserving Folder Structure
Yes. Upgrade to 1.1.34 if you want to use FileCopyDir for this.
14.3 & 1.3.7
Who is online
Users browsing this forum: docterry, Leonardo_Portela, sofista and 176 guests