像這樣的東西可能會給你你想要的結果。
files.to.keep <- c("ECGVW103899_wholecaseRRiQTi.rr",
"ECGVW104077_wholecaseRRiQTi.rr",
"ECGVW104081_wholecaseRRiQTi.rr",
"ECGVW104121_wholecaseRRiQTi.rr",
"ECGVW104182_wholecaseRRiQTi.rr")
source.path <- # Path to file source folder
destination.path <- # Path to file destination folder
# Create destination folder if it does not exist
ifelse(!dir.exists(destination.path), dir.create(destination.path), FALSE)
# Get list of files in source folder
filenames <- list.files(source.path)
# Move files that are not in files.to.keep to the destination folder
lapply(filenames, function(x)
if(!(x %in% files.to.keep))
{file.rename(from = file.path(source.path,x),to = file.path(destination.path,x))})
查看哪些文件不在您的列表中很容易使用索引。至於移動文件,請參閱[這裏](http://www.talkstats.com/showthread.php/21889-Move-files-from-one-folder-to-another-using-R) – RobertMc