can you not do a [ -s file ] in you cgi script?

From: Ronald J Kimball <[email protected]>
To: Summer <[email protected]>
Cc: [email protected]
Sent: Wednesday, June 22, 2011 9:29 AM
Subject: Re: [Templates] Way to test if a file has content or has a size 
greater than 0 in TT??

You could do this: 

[% file = INSERT "path/to/file" %]
[% file.length %]

Note that this will throw an error if the file does not exist.  You can use 
TT's TRY/CATCH to catch that error.

However, reading the entire file into memory just to find out its size is kind 
of a heavy solution.  Another option would be to pass a method to the template 
that just checks the size of the file with -s.

Ronald
On Tue, Jun 21, 2011 at 9:38 PM, Summer <[email protected]> wrote: 
Hey All,
>
>Given the normal distribution of template tookit, is there a way to test to 
>see if a file on the server has any content in it?
>
>I am requesting xml via ajax and in some instances a file or two might not 
>have any content though it still exists in the directory, so I don't even 
>wanna go and request the file if there is a way I can (in template toolkit) 
>determine if the file even exists or has any content.
>
>Is there any way to determine if somexmlfile.xml has some content associated 
>with it? Assign it to a var and then test the length of the var or somesuch?
>
>thanks.
> 
>_______________________________________________
>templates mailing list
>[email protected]
>http://mail.template-toolkit.org/mailman/listinfo/templates
>
>_______________________________________________templates mailing 
>[email protected]http://mail.template-toolkit.org/mailman/listinfo/templates
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to