Copy folder recursive in R

后端 未结 6 871
谎友^
谎友^ 2021-02-13 17:27

Am I missing something in the functions?
I want to copy a folder with some files and another subfolder from one location to another. I tried to use file.copy(from, to,

6条回答
  •  南旧
    南旧 (楼主)
    2021-02-13 18:25

    as @matifou says in the comments, the accepted answer by the questioneer himself is a bit confusing, because you end up with the copied folder inside a folder with the same name as the copied folder... to avoid this, do this instead:

    case: you want to move folder_X to folder_Z.

    # create empty folder Z inside folder X
    dir.create('(...)/folder_X/folder_Z')
    # copy the folder
    file.copy('(...)/path_to_folder_Z', '(...)/folder_X')
    

    so the second argument to file.copy shold be just folder_X, and not the newly created folder_Z inside folder_X.

    Because if you do that, the folder structure will be like this, which is probably not what you want:

    (...)/folder_X/folder_Z/folder_Z

    (Maybe this will save somebody the 10 minutes or so it took me to figure out)

提交回复
热议问题