Wednesday, April 12, 2006

 

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.

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?