[R] parsing dir output for file sizes

Uwe Ligges ligges at statistik.uni-dortmund.de
Tue Jul 11 08:39:06 CEST 2000

[Forgot to cc it to R-Help, so doing it now]

Griffith Feeney wrote:
> I've got an R wrapper around an old DOS program. In the R program I need to
> test whether the DOS program failed to produce certain output. This is
> indicated by certain text files created by the DOS program being empty.
> I can use system(command, intern=TRUE) to get the output of a DOS dir for a
> test file, but I'm having trouble parsing this to get the file size.
> Is there an R function to find the first occurrence of a character in a
> character string (seems there must be, but I'm at a loss to find it)? Or
> can anyone suggest a better approach?

I would try to write the listing of the directory DIRNAME into a file
After that you can scan(.) that file, search the FILENAME and the item
before the filename in your scanned dirfile.txt is the filesize:

 shell("dir DIRNAME > dirfile.txt")
 temp <- scan("dirfile.txt", what="character")

Uwe Ligges
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list