Copy folders from one directory to another in R

社会主义新天地 提交于 2019-12-04 22:52:18
Huang Chen

Copying your current directory files to their new directories

currentfiles is a list of files you want to copy newlocation is the directory you're copying to

If you aren't listing your current files, you'll need to loop through you're working directory

file.copy(from=currentfiles, to=newlocation, 
          overwrite = TRUE, recursive = FALSE, 
          copy.mode = TRUE)

This is for deleting your old files

file.remove(currentfiles)

I am late. This is my simple approach that gets things done. In R,

current_folder <- "C:/Users/Bhabani2077/Desktop/Current"
new_folder <- "C:/Users/Bhabani2077/Desktop/Ins"
list_of_files <- list.files(current_folder, ".py$") 
# ".py$" is the type of file you want to copy. Remove if copying all types of files. 
file.copy(file.path(current_folder,list_of_files), new_folder)
Neha Prasad

All of the solutions I've seen to this question seem to imply a Unix based operating system (Mac & Linux). I think the reason that the response(s) didn't work for OP is that OP may be on Windows.

In Windows, the definition of a file is just that, a file, whereas Unix defines a file as a file or directory. I believe this may be why file.copy() is not working, based on my understanding of the "File Manipulation" R documentation - arguments inputted to file.copy() for the "from" field must be files (not directories), but can be either files or directories for the "to" field.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!