Skip to main content
Participant
February 7, 2008
Question

File list() error

  • February 7, 2008
  • 4 replies
  • 1793 views
When I invoke myfile.list() where myfile is a directory, I get the following:

File operation File.position failed. File is in closed state("thefile.flv").

I get the above error in the log output of fms for every file in the directory. I just want the filenames.

Does anyone know what is happening here? All I want is a list of all the files in the directory, which I do get in the
error output of the server logs.

I'm using the developer edition fms 2.

Thanks in advance.
    This topic has been closed for replies.

    4 replies

    January 4, 2011

    On FMS 4, running

    /**

    * Return list of file in application folder with media duration

        * */

    Client.prototype.listFiles = function( folderName ) { 

    trace("ListFiles: /streams/" + folderName );

    var sessionDir = new File( "/streams/" + folderName +"/");

    var fileArray = sessionDir.list(

    //filter functions.  returns true to accept every file.

    function(name){

    return true;

    }

    );

    return fileArray; }

    I receive the following on FMS Live Log.

    ListFiles: /streams/00506308-174e-4146-b169-406c55519bb4

    Sending error message: File operation File.position failed. File is in closed state (/streams/00506308-174e-4146-b169-406c55519bb4/s188fee80-8783-4838-b011-a0385005b85b.flv).

    Participating Frequently
    January 5, 2011

    Now I was able to reproduce this issue at my end.

    Well, I tried something (where I am saving fileArray.name property into a different array and then returning back this new array instead of fileArray object) and it worked out well, you may also give it a try to see if it works for you as well:

    var filenames = new Object();

    Client.prototype.listFiles = function( folderName )
    {
      trace("ListFiles: /streams/" + folderName );
      var sessionDir = new File( "/workspace/" + folderName +"/");
      var fileArray = sessionDir.list();
      for(items in fileArray)
      {
        filenames = fileArray[items].name;
        i = i+1;
      }
      return filenames;
    }

    on client-side you can write something like this in your responder object:

             private function onReply(result:Object):void 
             { 
                 for (var tokens in result)
                 {
                    trace("$$: " + result[tokens]);
                 }
             }

    January 5, 2011

    Using your advice, I was able to get rid of the error.  I am also calculating the duration of the flv file and returning it so my my final code is

    Client.prototype.listFiles = function( folderName ) { 

    trace("ListFiles: /streams/" + folderName );

    var sessionDir = new File( "/streams/" + folderName +"/");

    var fileArray = sessionDir.list(

    //filter functions.  returns true to accept every file.

    function(name){

    return true;

    }

    );

    var rtnFiles = [];

    var i=0;

    for(items in fileArray)

    {

    rtnFiles.push( new Object() );

    var fullPath = fileArray[items].name;

    rtnFiles.fileName = fullPath.slice(fullPath.lastIndexOf("/")+1, -4);

    rtnFiles.creationTime =  fileArray[items].creationTime;

    try{

    //add flv duration length expando

    rtnFiles.duration = Stream.length(rtnFiles.fileName);

    }

    catch(e){ trace(e); }

        i = i+1;

    }

    return rtnFiles;

    }

    Participating Frequently
    January 4, 2011

    Guys,

    I just used following code and I don't see the error you are mentioning. I am using FMS4:

    application.onConnect = function(client)
    {
        trace("welcome...");
        return true;

    }


    Client.prototype.callme = function()
    {

      myDir = new File("/workspace/folder1");
      var files = myDir.list();
      for(items in files)
      {trace("items = " + files[items].name);}
    }

    Participating Frequently
    January 4, 2011

    Also tried with FMS 2.0.3.69 and found that same thing works fine there also. Can you please confirm if I am out of sync with your issue.

    January 2, 2011

    up up!!!

    Participating Frequently
    April 3, 2009
    Hi,
    I up this topic because I get exactly the same error message.
    Anyway, the function returned a list with all the files in the folder, but it generates a lot of log messages for... nothing.

    Why this function calls File.position ? Can I disable logs for this application ?
    Participating Frequently
    May 27, 2009

    Up !