Hi folks, I have a situation in which some files that were send over from a application is empty but with file size. As such I could not use filesize to determine if the file is empty. I have tried to count the number of lines but not successful. I have tried the code below but fail.
Thank you in advance for the help.
Set destination=C:\Inbox\ZeroKB
Set filename= C:\Inbox\ORD_SG_201108*.ASC
for %%a in (‘type %filename% ^|find “” /v /c’) do (IF %%a equ 0 copy /Y %%a %destination%)
If a file has a file size greater than zero then it is not empty. It may contain information that you cannot see with a text editor, perhaps just a lot of spaces but it is not empty. Or you have a serious problem with your file system that is misreporting file size.
This is how I solved the problem. It will check if the file exists first then check the length. I’d consider a non-existent file to be effectively empty.
var info = new FileInfo(filename);
if ((!info.Exists) || info.Length == 0)
{
// file is empty or non-existant
}