What is a quick (preferably OS independent) way to check whether a .txt file is empty using Mathematica?
FileByteCount will probably be the fastest way of checking strict emptiness. But what if you need to actually read the file (e.g. check integrity or catch some corner case)? Here's an alternative where the file content is checked, using
Read. In general, streams are the fastest way to read and write data in external files.
Generate your file list
Read the first word (
Number) of the file. If the file is empty, it should return the symbol
Map[Read[#, Word] &][filelist]
This gives you the option to run some test on the contents of the first lines of the file. Don't forget to close the opened streams so that you don't read subsequent lines if you repeat the command.
The only thing that is not cross-platform is the way the path to the working directory is written!
FileByteCount will give 0 for empty text files and is very fast (0.00003 seconds per file on my machine).