0

We have a folder with 4000 images. We would like to subset out a set of images into a new folder. We have a text file with a list of all of the images we would like to subset out. Is there an easy way to do this in windows or R?

user1977802
  • 313
  • 6
  • 10
  • 18

2 Answers2

1

This should work (not tested) with n the sample size:

n=100
newdir <- "C:\\Documents\\R\\wd\\text"
myfiles <- list.files()
mysample <- sample(myfiles,n)
file.copy(mysample,newdir)

See also this answer on moving files

JayCe
  • 241
  • 3
  • 9
1

Let's say you have a images.txt file with the filenames of the images you want to subset (each on a new line), then you can import the list with

images <- readLines("images.txt")

and make a new director and copy your subset with

dir.create("subset")
for (i in seq_along(images)) {
  file.copy(images[i], paste0("subset/", images[i]))
}

assuming your working directory is the folder with the images, e.g. with setwd() or using the here package.