1 Reply Latest reply on May 30, 2014 4:09 PM by mim_Armand

    Refresh File.length

    DBarranca Level 4


      in ExtendScript when I store a File object in a var like:


      var f = new File("~/Desktop/temp.jpg");


      I can check for properties such as the filesize:




      If the filesize changes after the variable has been declared and the value assigned, f.length doesn't reflect the correct number - I can understand the why.


      Since I need to dynamically test the filesize against a reference value in a function, I've been doing this way - which looks to my eyes a bit clumsy:


      function reduceToSize (fileObject, fileSize) {
          while(File(fileObject.fsName).length > fileSize) {
              // do stuff to reduce the file size


      This way I ensure that the reading is always up to date.

      I wonder whether this is the best/only way to have a live-updated reference of the file size (or any other File property).

      Thank you in advance for your comments,


      Davide Barranca




        • 1. Re: Refresh File.length
          mim_Armand Level 1

          Hi DBarranca,


          I'm new to Extend-Script but in my eyes with a bit experience in JavaScript, no, that's not the best way! and it's blocking! specially in this use case, but maybe you are right about that being the 'only' way,I did a bit research since I need something like that too, and apparently no timing function from javascript is implemented in Extend-Script!! (which is weird and not cool!!), but there is always some work arounds! as what I can think of right now:

          • using events objects* (which I'm not familiar with in Extend script but may there be any possibilities to use them is this situation?)
          • writing your own setinterval function, since fortunately Date object and all its atts are available in Extend-Script.*


          I don't really know if it helped you at all but I hope so,

          GL, mim


          *Edit: my apology, I tried setinterval custom function one, I tried so many different stuff but it just wont work without users interaction! (it kinda works otherwise but I don't think if it worth anything like that anyway!), I looked up events and event objects in documentation as well and there is just one which can kinda be helpful but I'm not even sure! (it was onIdle anyway!) so it looks pretty much like what you said: It's the only way to do that in Extend Script unfortunately! :/ (except if it's possible to write a custom event and listener which doesn't look likely!) there is $.sleep() tho but it is blocking and not useful in most of cases! really disappointing isn't it?! :/