0

I am using the function file.copy() and I have some issues. The idea is to copy files based on a list of file names from one folder to another. How can i set up the code to make it work.

list.files("C:/Test/PDF", recursive = TRUE) #

t<- read.csv2(file="C://Test//tes.csv") #is the list with the file names

a <- as.character(t[1:nrow(t),])

file.copy(a, "C:/Test/PDF verschoben" )

message:

problem copying .\Eidesstattliche.pdf to C:\Test\PDF verschoben\Eidesstattliche.pdf: No such file or directoryproblem copying .\Anmeldung_Defensio.pdf to C:\Test\PDF verschoben\Anmeldung_Defensio.pdf: No such file or directory[1]  TRUE FALSE  TRUE  TRUE FALSE`
list.files("C:/Test/PDF", recursive = TRUE)
[1] "1/2014_Bewerbung Mietwohnung_Loe.pdf" "1/Anmeldung_Defensio.pdf"             "1/Eidesstattliche.pdf"                "2/Anhang_unterzeichnet.pdf"          
[5] "2/Formular_unterschrieben.pdf"
a
[1] "Formular_unterschrieben.pdf"        "Eidesstattliche.pdf"                "Anhang_unterzeichnet.pdf"           "2014_Bewerbung Mietwohnung_Loe.pdf"

Any ideas?

Klini
  • 13
  • 4
  • But why and how the files you are listed are in the `tes.csv` file. Show us the result of `getwd()` and try `a <- list.files(list.files("C:/Test/PDF", recursive = TRUE)` and `file.copy(paste0("C:/Test/PDF/", a), "C:/Test/PDF verschoben" )`. – pietrodito Apr 14 '21 at 16:08
  • this is just only a test for a worklfow. i have a folder with almost 700 files and i need to move arround 400 of them to another folder. I got the 400 file names from a database as a csv. getwd() is "C:/Test/PDF" – Klini Apr 14 '21 at 16:18

1 Answers1

0

The question is not crystal clear, but the issue seems to be that list.files() does NOT return the entire path as you can see in the error message : copying .\Eidesstattliche.pdf.

I cannot see why and how the files you are listed are in the tes.csv file. Show us the result of getwd() and try:

a <- list.files(list.files("C:/Test/PDF", recursive = TRUE)
file.copy(paste0("C:/Test/PDF/", a), "C:/Test/PDF verschoben" )
pietrodito
  • 1,783
  • 15
  • 24