unzip a .zip file

I did this

dataFrom="E:/test/"
folderTo="E:/test2/"
s=list.files(dataFrom)
j=1`enter code here`
while(j<=length(s))
{
  unzip(paste(dataFrom,s[j], sep=""),exdir=folderTo)
  j=j+1
}

Answer is: exdir doesn't exist, and it exists, I created


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.

Tags:

R