I have thousands of text files and would like to know how to check if a particular file is empty. I am reading all the files using this line of code
Y<-grep(\
You can use file.info for that:
info = file.info(filenames)
empty = rownames(info[info$size == 0, ])
Incidentally, there’s a better way of listing text files than using grep
: specify the pattern
argument to list.files
:
list.files(pattern = '\\.txt$')
Notice that the pattern needs to be a regular expression, not a glob – the same is true for grep
!