Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions ExtendScript : Help with file selection

  • ExtendScript : Help with file selection

    Posted by Remi Monedi on October 28, 2022 at 7:25 pm

    Hi everyone,
    I’m starting to write scripts and now I’d like to be able to access files and folders on my computer (Windows) to import/replace footage in After Effects for instance.
    I have trouble finding answers to these questions, maybe you can point me in the right direction?

    This basic import script command works only for files with specific paths and names :

    var myFolder = "~/Desktop/";

    app.project.importFile(new ImportOptions(File(myFolder + "test.jpg")));

    – Is it possible to select the Xth file from a folder? (the 1st for instance)
    – Is it possible to select a file with a certain word in its name? (like “FINAL”)
    – Is it possible to select a random file of a specific format? (a JPG for instance)

    By selecting I mean, identifying the file I want to import or replace, …

    Have a great day!

    Remi Monedi replied 3 years, 5 months ago 2 Members · 2 Replies
  • 2 Replies
  • Tomas Bumbulevičius

    November 5, 2022 at 4:46 pm

    Hey Remi,

    few things based on your topics:
    1. I wouldn’t recommend relying on indexing of files in a folder – simply because there can be hidden files, or if your naming convention is not consistent – incorrect sorting.
    2. This would return all the files within a folder:

    var allFiles = (new Folder(locationPath)).getFiles(nameMask);

    Defining nameMask allows to filter out. Logic being its accordingly:
    a) “*FINAL” returns all files which has FINAL after any character.
    b) “FINAL” returns specifically named file.
    c) “*FINAL*” returns all files which has FINAL inbetween.

    Thus asterics allows to define characters either inclusive or not and helps to mask.

    3. The same filtering will help with extensions too.

    Now, once collected the files, run a loop of importing and it will do what you ask it to do – import those assets 🙂

  • Remi Monedi

    December 4, 2022 at 12:26 pm

    Hey Tomas! Thank you! Great explanation too!

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