Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Read a file with After Effects Script?

  • Read a file with After Effects Script?

    Posted by Joshua Faget on November 3, 2016 at 2:44 pm

    Hello,

    I want to open a file on the system and alert its contents, but for a reason which is unknown to me, the following script returns a blank alert box.

    I know that opening a .jpeg will return a bunch of characters and weird stuff, but that is what I actually want. I want the “source code” of the file.

    Maybe there is another workaround…. my goal is to get the binary data of the file.

    Thank you.

    var openFile = File.openDialog("r");
    var content = openFile.read();

    alert(content);

    Joshua Faget replied 9 years, 6 months ago 2 Members · 2 Replies
  • 2 Replies
  • Xavier Gomez

    November 3, 2016 at 3:48 pm

    The dialog will create a file object, but does not actually opens it for reading. This is another step:

    var file = File.openDialog();
    if (file && file.open(“r”)){
    var content = file.read();
    file.close();
    alert(content);
    };

    Xavier

  • Joshua Faget

    November 3, 2016 at 4:54 pm

    When I do the following, im getting a blank new file.

    I’d like to be able to duplicate a .jpg file for example that way, so halfway through I can mess with the building blocks of the file.

    var file = File.openDialog();
    if (file && file.open("r")){
    var content = file.read();
    file.close();

    //do stuff to var content here

    var save = File.saveDialog();
    var newFile = new File(save);
    newFile.open("w");
    newFile.write(content);
    newFile.close;

    };

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy