Unzip a .Zip File

Unzipping files in Python

import zipfile
with zipfile.ZipFile(path_to_zip_file, 'r') as zip_ref:
zip_ref.extractall(directory_to_extract_to)

That's pretty much it!

how to unzip a zip file inside another zip file?

No idea about Jenkins but what you need is a recursive function.

recursiveUnzip.sh

#!/bin/dash
recursiveUnzip () { # $1=directory
local path="$(realpath "$1")"
for file in "$path"/*; do
if [ -d "$file" ]; then
recursiveUnzip "$file"
elif [ -f "$file" -a "${file##*.}" = 'zip' ]; then
# unzip -d "${file%.zip}" "$file" # variation 1
unzip -d "${file%/*}" "$file" # variation 2
rm -f "$file" # comment this if you want to keep the zip files.
recursiveUnzip "${file%.zip}"
fi
done
}
recursiveUnzip "$1"

Then call the script like this

./recursiveUnzip.sh <directory>

In you case, probably like this

./recursiveUnzip.sh "$WORKSPACE"

unzip a .zip file

You could do it like this:

zipF<-file.choose() # lets you choose a file and save its file path in R (at least for windows)
outDir<-"C:\\Users\\Name\\Documents\\unzipfolder" # Define the folder where the zip file should be unzipped to
unzip(zipF,exdir=outDir) # unzip your file

Well you could also define both paths in R the classical way:

Assuming your zip file is named file.zip

zipF<- "C:\\path\\to\\my\\zipfile\\file.zip"
outDir<-"C:\\Users\\Name\\Documents\\unzipfolder"
unzip(zipF,exdir=outDir)

exdir defines the directory to extract files to. It will be created if not already available.
If you don't set exdir, unzip will just unzip it to your current working directory.

Download a large zipped CSV file, unzip and read into R on Linux

It might be a file permission issue. To get around it work in a directory you're already in, or know you have access to.


# DOWNLOAD THE FILE
# to a directory you can access, and name the file. No need to overcomplicate this.

download.file("https://download.cms.gov/nppes/NPPES_Data_Dissemination_February_2022.zip",
destfile = "/home/myName/myProjectname/npi.csv")

# use the decompress function if you need to, though unzip might work
x <- decompress_file(directory = "/home/myName/myProjectname/",
file = "npi.zip")

# remove .zip file if you need the space back
file.remove("/home/myName/myProjectname/npi.zip")

Unzip created zip folder to same folder?

If your file is a .zip file that should work. I tried this in a rar file that gave me error [System.IO.Invalid Data Exception] for checking that error you can go to that link.

End of Central Directory record could not be found

You are trying to unzip a file(.zip extension) to a File folder. That is what i understood from your question but in your code you gave a file location which has a .zip extension. It needs to be a File folder.
I made some changes check this one.

namespace ZipWorker
{
class Program
{
static void Main()
{
string pathInput;
string pathString;


do
{
Console.WriteLine("Please enter the path for the folder that you want to create");
pathString = Console.ReadLine();

} while (String.IsNullOrEmpty(pathString));


do
{
Console.WriteLine("Please enter the path for the Folder to copy");
pathInput = Console.ReadLine();

} while (String.IsNullOrEmpty(pathInput));


System.IO.Directory.CreateDirectory(pathString);


string fileName = System.IO.Path.GetFileName(pathInput);
if (fileName.Contains(".zip"))
{
fileName = fileName.Replace(".zip", "");
}

pathString = System.IO.Path.Combine(pathString, fileName) ;


Console.WriteLine("Path to my file: {0}\n", pathString);

if (!System.IO.Directory.Exists(pathString))
{
System.IO.Directory.CreateDirectory(pathString);
ZipFile.ExtractToDirectory(pathInput, pathString);

}
else
{
Console.WriteLine("File \"{0}\" already exists.", fileName);
return;
}
System.Console.WriteLine("Press any key to exit.");
System.Console.ReadKey();
}
}
}


Related Topics



Leave a reply



Submit