Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Can’t read filepath as File() makes whitespace to %20

  • Can’t read filepath as File() makes whitespace to %20

    Posted by Crystal Goh on August 30, 2020 at 4:03 am

    Hi,
    my script reads and takes data from a .txt outside of itself. It actually works until when I placed the .txt file into the ScriptUI Folder
    heres the issue atm

    var filPathStr = "~/Program Files/Adobe/Adobe After Effects 2020/Support Files/Scripts/ScriptUI/txt.txt";
    var dFile = File (filPathStr);

    //dFile = c/Program%20Files/Adobe/Adobe%20After%20Effects%202020/Support%20Files/Scripts/ScriptUI;

    I have tried a number of solutions, be it using replace(/%20/g, ” “) or decodeURI(str), but it does not work as they return a string than an object.

    so no matter how much I fix the string filPathStr, once I try place the string into File(), all whitespaces turn back to ‘%20′.
    I am not too sure if it is wise to remove the actual folders’ whitespaces of After effects, but i cant find any other way to deal with it

    Crystal Goh replied 6 years ago 3 Members · 7 Replies
  • 7 Replies
  • Filip Vandueren

    August 30, 2020 at 12:47 pm

    But why do you need to change the %20?
    The File object points to the File, does it not?

    What do you mean by “place the string into File()” ?

  • Filip Vandueren

    August 30, 2020 at 1:13 pm

    Once you’ve created the file with a path, you can get different properties of that file such as

    f.fsName; (dependant on your platform)
    f.fullName; (independant of platform)
    (on my mac these two are the same, I suppose on windows fsName would use reverse slashes)
    f.absoluteURI;
    f.relativeURI;
    f.path;

    But if you’re just asking what “f” is -> it’s an object representing a file,
    and if you $.writeln(f) it’s the same as $.writeln(f.toString)
    which happens to return f.absoluteURI.

    I think you want/expact f.fullName;
    although to just manipulate the file (read from it or write to it), there’s no need -> just use f

  • Crystal Goh

    August 30, 2020 at 1:55 pm

    I need it to change because the script Im working also will edit the contents in .txt after a button onClick, i have no clue why the file can read the .txt file and import its data in, but I can’t save in new data to it with these ‘%20’, even if im taking the same variable (f) containing the file in it


    var filPathStr = "~/Program Files/Adobe/Adobe After Effects 2020/Support Files/Scripts/ScriptUI/txt.txt";
    var f = File (filPathStr);
    // f == c/Program%20Files/Adobe/Adobe%20After%20Effects%202020/Support%20Files/Scripts/ScriptUI/txt.txt;

    f.open("w");
    f.write("data");
    f.close();

    // new data written into 'f' still not reflected in the txt.txt file

    Thing is the script is actually working, just that when %20 isnt involved in the file’s Path.

  • Filip Vandueren

    August 30, 2020 at 2:32 pm

    Are you sure that’s the case for every path with a space, and not due to your script not having the privileges to write to this specific path.

  • Crystal Goh

    August 30, 2020 at 5:01 pm

    Positive on that.

    But now that you mention that I think its really odd, I might probably do a factory reset or something because I used an older ver of the script in my workflow and that same line of code worked fine, maybe thats a solution for it

    Thank you!

  • Tomas Bumbulevičius

    September 2, 2020 at 10:15 am

    Hey Crystal, few ideas and suggestion from my end:

    1. It is wise to use space-separators instead of spaces in file names, thus then you don’t need to bother much about spacing compatibilities, especially cross-os. (But I get a problem of ‘Program Files’ (: )
    2. Buut, you shouldn’t do replacement of encoded characters in a string, as its not reliable (if there will be more encoded chars than spaces alone, solution will come shprt). Instead, using decodeURI(string), when string is built – all you need to do is generate a new file path, from a string:

    var yourNewFilePath = new File (decodedStringPath)

    Find out more:
    Motion Graphics Design & After Effects Tutorials
    On YT
    On VH

  • Crystal Goh

    September 2, 2020 at 12:54 pm

    Hi Tomas, thanks for taking the time for replying!

    Sadly I’ve tried those and they didnt turn out well..

    1- I felt it was risky to change /Adobe After Effects/ path, which official comes with the spaces, so I didn’t rouch it

    2- It was something I’ve tried, but it still returns back the %20, because I may have decoded the string, but once I made it back as a path using new File(), the %20 returns, like as if asking a new File encodes back the URI.

    Thanks for the comment still! Appreciate it

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