How move / copy 36000 files?

Hi community

In a another question Im make something very same to my current questions today .

Maybe was not the best solution but in this case worked well.

Now, I'm need move or copy 36.000 files to other order directory.

Im get the to path, source and destination. But when Im try to run my Rstudio collapse :smiling_face_with_tear:

# run well wit this example
df = data.frame(                                            
  source = c('\\\\ALLIANCEDFS.ALLIANCE.CGIAR.ORG\\CL07_GRPhistoric\\GRP_OPERATION\\DOCUMENTATION\\ODISEA GENESYS\\SERVIDOR ODISEA\\20230227\\bean\\seed/G    1.jpg',
             '\\\\ALLIANCEDFS.ALLIANCE.CGIAR.ORG\\CL07_GRPhistoric\\GRP_OPERATION\\DOCUMENTATION\\ODISEA GENESYS\\SERVIDOR ODISEA\\20230227\\bean\\seed/G    2.jpg',
             '\\\\ALLIANCEDFS.ALLIANCE.CGIAR.ORG\\CL07_GRPhistoric\\GRP_OPERATION\\DOCUMENTATION\\ODISEA GENESYS\\SERVIDOR ODISEA\\20230227\\bean\\seed/G    3.jpg',
             '\\\\ALLIANCEDFS.ALLIANCE.CGIAR.ORG\\CL07_GRPhistoric\\GRP_OPERATION\\DOCUMENTATION\\ODISEA GENESYS\\SERVIDOR ODISEA\\20230227\\bean\\seed/G    4.jpg',
             '\\\\ALLIANCEDFS.ALLIANCE.CGIAR.ORG\\CL07_GRPhistoric\\GRP_OPERATION\\DOCUMENTATION\\ODISEA GENESYS\\SERVIDOR ODISEA\\20230227\\bean\\seed/G    5.jpg'),
  destination = c('\\\\ALLIANCEDFS.ALLIANCE.CGIAR.ORG\\CL07_GRPhistoric\\GRP_OPERATION\\DOCUMENTATION\\ODISEA GENESYS\\SERVIDOR GENESYS\\20230303\\acn\\G1\\G1 seed.jpg',
                  '\\\\ALLIANCEDFS.ALLIANCE.CGIAR.ORG\\CL07_GRPhistoric\\GRP_OPERATION\\DOCUMENTATION\\ODISEA GENESYS\\SERVIDOR GENESYS\\20230303\\acn\\G2\\G2 seed.jpg',
                  '\\\\ALLIANCEDFS.ALLIANCE.CGIAR.ORG\\CL07_GRPhistoric\\GRP_OPERATION\\DOCUMENTATION\\ODISEA GENESYS\\SERVIDOR GENESYS\\20230303\\acn\\G3\\G3 seed.jpg',
                  '\\\\ALLIANCEDFS.ALLIANCE.CGIAR.ORG\\CL07_GRPhistoric\\GRP_OPERATION\\DOCUMENTATION\\ODISEA GENESYS\\SERVIDOR GENESYS\\20230303\\acn\\G4\\G4 seed.jpg',
                  '\\\\ALLIANCEDFS.ALLIANCE.CGIAR.ORG\\CL07_GRPhistoric\\GRP_OPERATION\\DOCUMENTATION\\ODISEA GENESYS\\SERVIDOR GENESYS\\20230303\\acn\\G5\\G5 seed.jpg'))

file.copy(from = df$source, to = df$destination)

url <- "https://docs.google.com/spreadsheets/d/1qoHxBRfchDanYc8pvTH8esa6ANL-N-Ja/edit#gid=430580483/export?format=xlsx"

download.file(url, "acn.xlsx")

Im get the all the path, because create the destination folders.

# Im try with this other form but the path source are not correct

source_dir <- '\\\\ALLIANCEDFS.ALLIANCE.CGIAR.ORG\\CL07_GRPhistoric\\GRP_OPERATION\\DOCUMENTATION\\ODISEA GENESYS\\SERVIDOR ODISEA\\20230227\\bean\\seed\\'
dest_dir <- '\\\\ALLIANCEDFS.ALLIANCE.CGIAR.ORG\\CL07_GRPhistoric\\GRP_OPERATION\\DOCUMENTATION\\ODISEA GENESYS\\SERVIDOR GENESYS\\20230303\\acn\\'

# loop over the file numbers and copy each file
for (i in 1:5) {
  source_file <- paste0(source_dir,'G', i ,'.jpg')
  dest_file <- paste0(dest_dir, 'G', i, '\\G', i, ' seed.jpg')
  file.copy(from = source_file, to = dest_file)
}

Any suggest, or link or other way is very useful.

You could use list.files() to get all the file names, then move them to the other folder. It would probably be faster to use purrr::map() than to use a for loop. But even so, that many files would take a long time.

Example:

library(glue)

# create folders and files -----------
dir.create("folder_a")
purrr::map(1:100, ~file.create(glue("folder_a/{.x}.csv"))) # 100 test files

# list of files -----------
files_to_move <- list.files("folder_a")
files_to_move_locations <- fs::dir_ls("folder_a")

# create new folder -------------
dir.create("folder_b")

# move to new folder -----------
purrr::map2(files_to_move_locations, files_to_move,  ~fs::file_move(.x, glue("folder_b/{.y}")))


It could be better/faster to use Shell/Powershell to do it.

Move files in the Linux terminal | Opensource.com

Whatever you do would probably take a long time.

2 Likes

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.