Jump to content
Sign in to follow this  
handyt2

Empty File, but may contain blank line(s)

Recommended Posts

handyt2

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 ..

Share this post


Link to post
Share on other sites
JLogan3o13

How about a simple FileRead?

$sFile = @DesktopDir & "\Test.txt"
$sString = FileRead($sFile)
 MsgBox(0, "", ($sString = "") ? "File is empty." : "File contains data of some sort.")
  • Like 1

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
kylomas

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

  • Like 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

Share this post


Link to post
Share on other sites
kylomas

and another...

ConsoleWrite((_IsFileEmpty(@scriptdir & '\test.txt') ) ? 'No' & @CRLF : 'Yes' & @CRLF)

func _IsFileEmpty($file)
    return (stringregexp(fileread($file),'.')) ? 1 : 0
endfunc
  • Like 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

Share this post


Link to post
Share on other sites
handyt2

Thanx all.. 

I opted for the Regexp .. i tested with a file with lots of blank lines & still works :)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×