Read and write kmls to

Dear all,
How can I read kmls from subdirectories and write them into a new single folder? I tried to do that using a loop, but it didn't work.


ls = list.files()
for(i in ls){
  my_data = lapply(rs, readOGR) 
  ss = list(my_data, makeUniqueIDs = T) %>% 
    flatten() %>%, .)
  writeOGR(ss, dsn= "new_dir", layer="polygon", driver="KML")

As we can't rerun your example, can you say what does not work exactly ?

After I create a list of polygons from different sub directories and specify new single directory, I use the writeOGR function to copy and paste each single polygon to the new directory, but it is only write one polygon to the new directory.