0
Cool Number
Hey all back with another niche article, for you all. Automate simple/mundane tasks to minimize effort.
I was recently asked to migrate SCORM files from local SFTP server to Oracle Learning Cloud. I chose to automate end to end task flow using R. In this article, we will go through an R program to download/zip files in required format.
library(RCurl)
setwd("C:\Users\amalla\Desktop\ORC\Scorm files")
Sys.setenv(R_ZIPCMD = "C:\Oracle\Middleware\Oracle_Home\oracle_common\adr\zip.exe")
my_wd<-getwd() # save your current working directory path
dest_path<-paste0(getwd(), "/Feb 23/scorm", i, "/")
setwd(dest_path)
files<-list.files(dest_path)
named<-paste0(dest_path,".zip")
mapply(zip,zipfile=named,files=files)
setwd(my_wd) # reset working directory path
# zip files in each sub folder
files <- list.files(path= paste0(getwd(), "/files/scorm"))
files <- readxl::read_excel(path = "Active Courses Final OD.xlsx", sheet = "Sheet2")
for (i in 1:length(files$name3)) {
my_wd<-"C://Users//amalla//Desktop//ORC//Scorm files" # save your current working directory path
dest_path<-paste0(my_wd, str_replace_all(files[i, "name3"], "/", "//"))
#if(!file.exists(dest_path)) { print(paste0("skipped: ", i));setwd(my_wd); next }
try(setwd(dest_path),silent = TRUE) = chgdir
if(class(chgdir)=="try-error") {print(paste0("skipped: ", i));
setwd(my_wd);
next }
l<-list.files(dest_path)
named<-paste0(files[i, "zipfoldername"],".zip")
if(file.exists(named)){file.copy(named, paste0(my_wd,"/zipp"));
setwd(my_wd);
next}
mapply(zip,zipfile=named,files=l)
file.copy(named, paste0(my_wd,"/zipp"))
# zip(zipfile= named, files= l, zip = Sys.getenv("R_ZIPCMD"),extras = '-j')
setwd(my_wd) # reset working directory path
}