Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Javascript: path.join variable strings?

  • Javascript: path.join variable strings?

    Posted by Bryan Woods on October 2, 2015 at 11:11 pm

    Having a problem here trying to combine two variables that are strings.

    I have two variables:
    var textFile = Folder.selectDialog();
    var textName = “filename.txt”;

    textFile should have a string of the directory I selected from the dialog window, right? If so, then I’m assuming I could combine these two variables without having to write any “\” or “/” and just let the code put them in based on the OS, correct?

    So why doesn’t path.join(textFile,textName) not do anything? It errors silently, so I can’t find out why its failing. Just nothing happens once it reaches this point in my code.

    Dan Ebberts replied 10 years, 10 months ago 2 Members · 7 Replies
  • 7 Replies
  • Dan Ebberts

    October 2, 2015 at 11:32 pm

    I’d just combine them into Adobe’s URI format. I usually do it like this:

    var textFolder = Folder.selectDialog();
    var textName = “filename.txt”;
    var textFilePath = textFolder.path + “/” + textFolder.name + “/” + escape(textName);

    Dan

  • Bryan Woods

    October 3, 2015 at 12:05 am

    Yeah, normally I would do this too. But I don’t know what platform this script will be used on, so I’m trying to join these two variables and get the proper slashes for free. Any suggestions?

  • Dan Ebberts

    October 3, 2015 at 6:05 pm

    So this wouldn’t be running in an ExtendScript environment? If that’s the case, I don’t know. Otherwise URI should work on any platform.

    Dan

  • Bryan Woods

    October 4, 2015 at 5:30 am

    Well, its a script intended for after effects, I just don’t know if it will be used on PCs or Macs, so i’m trying to make this thing flexible as possible and combine file paths and file names together and have proper slashes in the path.

  • Dan Ebberts

    October 4, 2015 at 5:57 am

    That’s the beauty of URI. It’s simple, After Effects understands it and does the necessary conversion to the format of the host machine.

    Dan

  • Bryan Woods

    October 4, 2015 at 3:26 pm

    I guess I’m just not following what you mean by the URI. If I used this code:

    var textFolder = Folder.selectDialog();
    var textName = "filename.txt";
    var textFilePath = textFolder.path + "/" + textFolder.name + "/" + escape(textName);

    You mean to tell me that those “/” that you have in there manually will be put in correctly based on the OS? So if I’m on a PC and run this script, i’d get “\” instead?

  • Dan Ebberts

    October 4, 2015 at 4:21 pm

    Exactly. Check out URI in Adobe’s JavaScript Tools Guide. It’s in the Specifying Paths section of the File System Access chapter.

    Dan

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