handyt2 Posted January 29, 2015 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 ..
Moderators JLogan3o13 Posted January 30, 2015 Moderators 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!
kylomas Posted January 30, 2015 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
Solution kylomas Posted January 30, 2015 Solution 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
handyt2 Posted January 30, 2015 Author Posted January 30, 2015 Thanx all.. I opted for the Regexp .. i tested with a file with lots of blank lines & still works
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