Jump to content

Empty File, but may contain blank line(s)


handyt2
 Share

Go to solution Solved by kylomas,

Recommended Posts

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

  • Moderators

How about a simple FileRead?

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

"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

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

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

  • Solution

and another...

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

func _IsFileEmpty($file)
    return (stringregexp(fileread($file),'.')) ? 1 : 0
endfunc

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...