If you just want to have the number of lines in each file, then I'd actually recommend using the command line tool
wc
: it will be much faster.
wc -l *.csv
will give you an ASCII table with the number of lines in the first column and the file name thereafter.
(wc
for the Windows command line is available e.g. as part of the GNU core utilities.)If it is about doing something for each .csv file in the directory, use
file = Sys.glob (paste0 (directory, "/*.csv")
Anyways, here's what you asked for more specifically:
directory = 'specdata'
id = 1:17
file = sprintf ("%s/%03i.csv", directory, id) # now a vector with file names
casenum = sapply (file, function (f) nrow (read.csv (f)))
cbind (id, casenum)
# or, if you prefer a data.frame
data.frame (id = id, casenum = casenum)