This may be a very common problem, so I am specifically looking for an elegant or at least less-kludgy-than-mine solution.
I have series of files from 001.csv to 200.csv
A combination of formatC()
and paste0()
should work:
paste0(formatC(1:200, width = 3, format = "d", flag = 0), ".csv")
This would be a good use of the sprintf
function. It has many formatting options, but for this case I would use
sprintf("%03d.csv", 1:200)
# [1] "001.csv" "002.csv" "003.csv" "004.csv" "005.csv"
# [6] "006.csv" "007.csv" "008.csv" "009.csv" "010.csv"
# ...
# [96] "096.csv" "097.csv" "098.csv" "099.csv" "100.csv"
# [101] "101.csv" "102.csv" "103.csv" "104.csv" "105.csv"
# ...
# [191] "191.csv" "192.csv" "193.csv" "194.csv" "195.csv"
# [196] "196.csv" "197.csv" "198.csv" "199.csv" "200.csv"