Skip to main content
Inspiring
July 28, 2022
Answered

AE Scripting: file.exists, file.open, file.close is undefined

  • July 28, 2022
  • 2 replies
  • 971 views

Hi,

I have an automation script that reads from a json file to do various things.  For months, the utility function which reads the json file has worked perfectly.  Suddenly today, it's causing an error that

"file.exists is undefined", same for file.open() and file.close()
What the hell is going on?  It's prbably something stupidly simple but I can't solve it. 

var jsonfile= File("X:/some/path/this.json");
jsondata = readJson(jsonfile)


function readJson(file){

  if (file.exists()){
    file.close() //if left open
    file.open("r");
    while(!file.eof){
      line = file.readln() ;
      data.push(line) ;
      data = data.join("") ;
      var parsedData = JSON.parse(data);
      return parsedData ;
    }
    file.close();
  }

}

This topic has been closed for replies.
Correct answer brianm60674866

to be more specific:

aep = thisArray[1]
alert (aep)

>>"X:/some/path/project.aep"

aep_file = File(aep);
alert(aep_file);
>> "/x/some/other/path/X:/some/path/project.aep"

On the other hand, if i explicity cast the variable

to be more specific:

aep = "X:/some/path/project.aep"
alert (aep)

>>"X:/some/path/project.aep"

aep_file = File(aep);
alert(aep_file);
>> "/x/some/path/project.aep"

And the problems continue...
startframe = thisArray[2] //value ="1001", type string
alert(startframe)
>>1001
startframe = parseInt(thisArray[2]) //value ="1001", type string
alert(startframe)
>>NaN

This is infuriatingly difficult.  I need to run a batch process that opens up spcific project files, edits comps and layer properties, and then moves on to the next one.  But I'm stuck on parsing data types which seems to be forbidden knowledge.

2 replies

Inspiring
July 28, 2022

Here's a new one...

var aep = 'X:/some/path/project.aep';
alert(aep);

//alerts "X:/some/path/project.aep"

aep_file = File(aep);
alert(aep_file);
//alerts "X:/some/other/path/X:/some/path/project.aep"

app.ope(aep_file)
Error: "...path is not valid"
No sh-t.  Why is it adding an additional path when I've explicity told it what the path is?

Dan Ebberts
Community Expert
Community Expert
July 28, 2022

This works perfectly for me:

var aep = '/c/test/project.aep';
var aep_file = File(aep);
app.open(aep_file);
Inspiring
July 28, 2022

Nevermind. 
I got rid of the file check:  file.exists()  and it seems to be working again. 

Kinda dumb. 
Was AE scripting intentionally designed to be difficult and counterintuitive?

Dan Ebberts
Community Expert
Community Expert
July 28, 2022

file.exists is a property, not a method, so I would expect file.exists() to cause problems.