Thursday, January 22, 2015

R - Extract several zipped files into a single folder

# read zipped files and extract tif or jpeg files from the bottom most folder

I have downloaded 4200 1' Orthoimagery raster files from USGS. Each zipped folder has several subfolder and then you will find the raster files.




The goal is to get raster files from all the zipped folder into a single folder.

setwd("I:/J_Prashant's External HD/High Speed Rail/GIS/Bulk Data/Bulk data/Firm Panels/")

output_location <- "output_folder"
dir.create(output_location)

zipped_files <- list.files()
zipped_files <- zipped_files[grepl(".zip", zipped_files)]

for (eachFile in zipped_files) {
  unzip(zipfile = eachFile, exdir = output_location, junkpaths = TRUE)
}


No comments:

Post a Comment