I will have list of source path & destination path in excel,
How can I move these files
| source | destination |
|---|---|
| C:/users/desk/1/a.pdf | C:/users/desktop/2 |
| C:/users/desk/1/b.pdf | C:/users/desktop/3 |
| C:/users/desk/1/abb.pdf | C:/users/desktop/56 |
I need to copy a file from particular source to respective given destination.
To copy the files, you can use
file.copy. This accepts avector ofsingle directory, or a vector of file paths as destinations, and copies the files to the new directory/paths.As your destination column contains only directory paths, you need to specify full paths (including file names) for new files. To do this, you can use
file.pathandbasenameto concatenate the original file names (insource) to the new directories (destination).To move the files, you can use
file.rename.Note 1:
file.renamemay only work when moving files between locations on the same drive. To move files across drives you could usefile.copyfollowed byfile.removeto remove the original files after copying. If doing this, you should be careful not to remove files if the copy operation fails, e.g.:Note 2: This is all assuming that you have read in your excel data using one of
read.csvordata.table::fread(for.csvfiles) orreadxl::read_excel(for.xlsor.xlsxfiles)