54 lines
1.5 KiB
R
54 lines
1.5 KiB
R
require(lubridate)
|
|
require(tidyverse)
|
|
|
|
fromBasePath = '/share/transport_4d'
|
|
toBasePath = '/share/mmbi/radar2/data/archive'
|
|
|
|
currDay = today()
|
|
|
|
getTraverseDirectory = function(aDate) {
|
|
dirPattern = format(aDate, format = '%Y-%m')
|
|
dirsGlimsExport = list.dirs(path = fromBasePath, full.names = F)
|
|
|
|
return(dirsGlimsExport[which(str_detect(dirsGlimsExport, dirPattern))])
|
|
|
|
}
|
|
|
|
getFilesToCopy = function(aDate, aDir) {
|
|
filesGlimsExport = list.files(aDir)
|
|
|
|
filePattern = format(aDate, format = '%y%m%d')
|
|
|
|
return(filesGlimsExport[which(str_detect(filesGlimsExport, filePattern))])
|
|
}
|
|
|
|
copyFiles = function(aDate, overwrite = F, verbose = T) {
|
|
traverseDir = getTraverseDirectory(aDate)
|
|
fromDir = file.path(fromBasePath, traverseDir)
|
|
toDir = file.path(toBasePath, traverseDir)
|
|
filesToCopy = getFilesToCopy(aDate, fromDir)
|
|
if (verbose)
|
|
cat(paste0('\nCopying from ', fromDir, ' => ', toDir, ' ..\n'))
|
|
for (f in filesToCopy) {
|
|
copySuccess = file.copy(from = file.path(fromDir, f),
|
|
to = file.path(toDir, f),
|
|
overwrite = overwrite,
|
|
copy.mode = T,
|
|
copy.date = T)
|
|
cat(paste0(f, '\11', copySuccess, '\n'))
|
|
}
|
|
}
|
|
|
|
copyFilesDateRange = function(nDays) {
|
|
ds = today() - nDays
|
|
d8s = ds + 1:nDays
|
|
for (d in 1:length(d8s)) {
|
|
d8 = d8s[d]
|
|
cat(paste0('copyFiles(', d8, ')\n'))
|
|
copyFiles(d8, verbose = F)
|
|
}
|
|
}
|
|
|
|
|
|
copyFilesDateRange(nDays = 3)
|