How can I check if a file is empty?

后端 未结 4 2084
春和景丽
春和景丽 2021-02-18 18:51

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(\         


        
4条回答
  •  时光取名叫无心
    2021-02-18 19:42

    For a functional approach, you might first write a predicate:

    file.empty <- function(filenames) file.info(filenames)$size == 0
    

    And then filter the list of files using it:

    Filter(file.empty, dir())
    

提交回复
热议问题