3
Hello, I have a problem.
I have a dummy directory that contains a set of folders, each folder within itself contains a protocol folder, and within each folder I have one or more files. Ex:
Pasta Protocolo Arquivo(s)
A -> 1 -> x
B -> 2 -> y
C -> 1 -> z , x
My challenge is to transfer the protocol folders to a new directory and put the files inside those folders without overwriting them. So the ideal result would be:
Protocolo Arquivo(s)
1 -> x (1) , x (2) , z
2 -> y
The folder and protocol are broken down into a df(test), so I’m creating these directories with a loop:
for (i in 1:3){
print(i)
pasta_to <- paste("F:/",
test$pasta[i], sep="/")
# Cria o diretório se ele não existe
ifelse(!dir.exists(pasta_to),
dir.create(pasta_to, recursive=TRUE), FALSE)
pasta_from = paste("C:/Meus Documentos/destino",
test$pasta_origem[i],
test$pasta_do_anexo_resposta[i],
sep="/")
files_from <- list.files(pasta_from)
path_from <- paste(pasta_from, files_from, sep="/")
file.copy(from=path_from, to = pasta_to, overwrite = F)
}
With this code he ends up overwriting the files with the same name x:
Protocolo Arquivo(s)
1 -> x , z
2 -> y
How do I not overwrite files?
One remark: in the real case, I don’t know the name of the files, so I couldn’t use a ifelse(file exists.())
– Jessica Voigt