remove multiple sequenced files in R -
i created multiple files named 1:100 + random letter file:
for (i in 1:100){ file.create( paste0(i , ".txt"), showwarnings=true) # assign random letter files az <- sample(letters,1) cat(az,file = paste0(i,".txt"),append=true) #rename files, , create new file append of letters name <- scan(file=paste0(i,".txt"), what="character") file.rename(paste0(i,".txt"), paste0(i, name,".txt"))
now, have lot of files named "1t, 2c, 3y,..., 100a" , want remove these files (not removing rest has in directory) file.remove function, how should remove them without naming 1 one? , directory named "exercicio03" inside?
ps.: have tried
file.remove(paste0(i,name,".txt"))
but removing last file "100a"
since used sample function, think can 100% sure remove these files , no others, if (did) save values became sample function. first part should have been:
az<-na (i in 1:100){ file.create( paste0(i , ".txt"), showwarnings=true) # assign random letter files az[i] <- sample(letters,1) cat(az[i],file = paste0(i,".txt"),append=true) #rename files, , create new file append of letters name <- scan(file=paste0(i,".txt"), what="character") file.rename(paste0(i,".txt"), paste0(i, name,".txt")) }
that way can afterwards remove them via :
(i in 1:100){ file.remove(paste0(i,az[i],".txt")) }
Comments
Post a Comment