Pages

Tuesday, August 28, 2018

Can a non existent file have a parent

Can a non existent file have a parent


I was suddenly unsure about this, so I ran a quick test:
//DESCRIPTION: Can a non-existent file have a parent?

defFile = File(getScriptPath().parent.fsName + "/test.txt");
parFile = defFile.parent;
alert(parFile.fsName);

function getScriptPath() {
  // This function returns the path to the active script, even when running ESTK
  try {
    return app.activeScript;
  } catch(e) {
    return File(e.fileName);
  }
}
And the answer is yes!

The explanation is fairly simple. Whether or not the file exists, the file object does exist. And, in order to exist, it must have a parent, the folder in which the corresponding file will be created should the script go the next step and create the file.

visit link download

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.