handyt2 Posted January 29, 2015 Share Posted January 29, 2015 I have to process incoming files in a landing folder. I use method similar to this to detect if the file is empty, I won't process it. '?do=embed' frameborder='0' data-embedContent>> the problem is, sometimes files can contain 1 or 2 blank lines.. and i consider this empty files as well.. so what's a good method of detecting that file contains (any) number of blank lines ..? Thanx .. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted January 30, 2015 Moderators Share Posted January 30, 2015 How about a simple FileRead? $sFile = @DesktopDir & "\Test.txt" $sString = FileRead($sFile) MsgBox(0, "", ($sString = "") ? "File is empty." : "File contains data of some sort.") handyt2 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
kylomas Posted January 30, 2015 Share Posted January 30, 2015 handyt2, One way to do it... ConsoleWrite((_IsFileEmpty(@scriptdir & '\test.txt') ) ? 'No' & @CRLF : 'Yes' & @CRLF) func _IsFileEmpty($file) return stringlen(stringreplace(fileread($file),@crlf,'')) endfunc kylomas handyt2 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Solution kylomas Posted January 30, 2015 Solution Share Posted January 30, 2015 and another... ConsoleWrite((_IsFileEmpty(@scriptdir & '\test.txt') ) ? 'No' & @CRLF : 'Yes' & @CRLF) func _IsFileEmpty($file) return (stringregexp(fileread($file),'.')) ? 1 : 0 endfunc handyt2 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
handyt2 Posted January 30, 2015 Author Share Posted January 30, 2015 Thanx all.. I opted for the Regexp .. i tested with a file with lots of blank lines & still works Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now