Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

General Discussions

Discuss any topics that are not product-specific here.
SOLVED

How To Zip A file Without Including Parent Directory

brianvtran
7 - Meteor

Hi,

 

I managed to get Alteryx to automate zipping a file using Run Command using a batch file written with Alteryx but there are extraneous paths in my Zipped Folder.

 

For example,

 

instead of having it be Zipped Folder --> csv file, 

it's giving me Zipped Folder--> Output Folder--> csv file.

 

Currently my batch file looks like this:

 

7z a -tzip "Zipped Folder pathway" "Folder where csv file to be zipped is found" 

 

I've seen suggestions about using -j and -r but I get either error 1 or error 7 since I'm not too familiar with CMD language. 

 

Is there any way to rewrite the batch file so that I can write and zip a csv file without all those extra paths? 

 

Thanks,

 

Brian

10 REPLIES 10
AkimasaKajitani
17 - Castor
17 - Castor

Hi @brianvtran 

 

Please try to specify the files(can use wildcard) instead of the folder.

It seems that it contains the parent folder or not depending on how to specify it.

 

For example,

 

7z a -tzip "c:\temp\ziptest\test.zip" "c:\temp\ziptest\*.*" => doesn't contain folder path(ziptest)

7z a -tzip "c:\temp\ziptest\test.zip" "c:\temp\ziptest" => contain folder path(ziptest)

 

brianvtran
7 - Meteor

Hey @AkimasaKajitani 

 

Thanks for the suggestion, I think it worked!

 

Thanks a lot

brianvtran
7 - Meteor

@AkimasaKajitani 

 

Do you happen to know a way to zip a file without using 7zip? I'm using a Windows machine and tried googling different methods like using tar.exe or powershell but I'm having trouble making them work since I'm not familiar with those applications and the way to write them. 

 

As much as I like the 7zip method, I noticed that sending the file to a compressed zipped folder via Windows has a faster processing time than 7zip. Ideally, if I have larger files to compress, I would like to opt for the zip method with the faster processing time. 

IraWatt
17 - Castor
17 - Castor

Hey @brianvtran,

You can try my Zip File Tool from the gallery Zip File Tool - Alteryx Community.

AkimasaKajitani
17 - Castor
17 - Castor

Hi @brianvtran 

 

You can also use powershell compress-archive command.

 

Command sample : compress-archive -Force images\*.* output

 

AkimasaKajitani_0-1657067629559.png

 

Please try it.

brianvtran
7 - Meteor

@AkimasaKajitani 

 

Is it enough for me to simply type in Powershell into the Run External Program? I tried browsing for the app location but not sure which one it would be listed under. I try to pick the WindowsPowershell folder under Programs but it branches out into Configurations and Modules and am not sure which folder to pick for the filepath to the Powershell program. 

 

Also what is -Force images/*.*? I understand Compress-Archive is the zip compression command but not sure what the 2nd half of the command argument is saying. I've seen other threads that mention Compress-Archive -Path "filepath" -DestinationPath "filepath.zip" but not sure how I would translate this to be dynamic since I was hoping to write it as

 

Compress-Archive -Path "filepath\[FileName].csv" -DestinationPath "filepath\[FileName].zip"

 

using the string to stand in dynamically for the filename. I considered writing this as a batch file but not sure how well Powershell reads batch files or if I would be writing it correctly for it to read the command if I were to do a similar set-up as the 7zip configuration you showed me previously. If I did, I'd run into the same issue of finding the correct folder where the Powershell app is stored. 

AkimasaKajitani
17 - Castor
17 - Castor

Hi @brianvtran ,


Sorry for the simple post. I would like to explain the detail.

 

PowerShell is standard application for Windows. PowerShell is in C:\Windows\System32. So, basically we don't need to specify the full path. To know the full path of PowerShell, we can see the property of shortcut of PowerShell.exe.

 

-Force : This option is to run the archive command without confirmation to the user. If there is the same name of the output file in output folder without this option, this command will stop and confirm to the user.

 

I would like to explain the command detail.

 

The sample is as follows.
compress-archive -Force images\*.* output
=> compress-archive -Force Compress-Archive-Path DestinationPath

 

"images\*.*" is compress archive path.
"output" is destination path.


If you have any question, let me know.

brianvtran
7 - Meteor

Hi @AkimasaKajitani 

 

After trying out your suggestion and reworking my language, I managed to get Alteryx to execute Powershell,

I had to write it as

 

Compress-Archive -Force -LiteralPath "File.csv" -DestinationPath "File.zip"

 

So this works wonders for the most part but as I attempted to compress larger files, I realized Powershell would not zip my files past a certain size. According to my research, it seems like Powershell cannot process files larger than 2GB due to the nature of something called the API(?). Would there happen to be any way for Powershell to compress 2+GB files or is this a natural limitation of the program? 

AkimasaKajitani
17 - Castor
17 - Castor

Hi @brianvtran 

 

According to the MS document, as you said there is a limitation of maximum file size(2GB).

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.archive/compress-archive?vie...

 

If you want to compress large file, you need to use 7z.

Labels