Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions import files with getFiles – multiple extensions/file types

  • import files with getFiles – multiple extensions/file types

    Posted by Goran Hanzek on November 4, 2019 at 10:22 am

    I want to import only mp4 and mpg files. I use this simple code where I can decide which file type to import but I don’t know how to allow more file extensions to be imported. Example below imports only .mp4 files. Putting “or” (||) between file types doesn’t help.

    var importVideoExtension = "*.mp4";
    var a = Folder(filePath);
    if(a != null){
    var b = a.getFiles(importVideoExtension);
    var c = b.length;
    for(var i = 0; i < c; i++){
    imported[i] = importAFile(b[i]);
    imported[i].parentFolder = footage;
    }
    }

    Goran Hanzek replied 6 years, 9 months ago 2 Members · 2 Replies
  • 2 Replies
  • Scott Mcgee

    November 4, 2019 at 1:36 pm

    I’m not sure if there is another way of doing it, but I use regex. I’ve tried it a few other ways with no success.

    Now I’ve not tested below out, but with my plugin this works.

    your script with amend
    var importVideoExtension = (/\.(mp4|mpg)$/i);
    var a = Folder(filePath);
    if(a != null){
    var b = a.getFiles(importVideoExtension);
    var c = b.length;
    for(var i = 0; i < c; i++){
    imported[i] = importAFile(b[i]);
    imported[i].parentFolder = footage;
    }
    }

    my script that works incase you can you modify this if the above doesn’t work.
    var file_type = (/\.(mp4|mp3)$/i);
    var sourceFolder = Folder.selectDialog(“Select folder with source files”);

    var sourceFiles = sourceFolder.getFiles(file_type);
    var footage;

    for (var i = 0; i < sourceFiles.length; i++) {
    footage = app.project.importFile(new ImportOptions(sourceFiles[i]));
    }

  • Goran Hanzek

    November 5, 2019 at 2:12 pm

    Thanks for fast reply and solution!

    In the meantime I also managed to solve it in a different way.
    I just have to tweak indexOf a little bit so that it doesn’t import files that have mp4 in their filename.
    I added couple of parameters besides fileObj instanceof File

    Here is my solution:

    var a = Folder(filePath);
    if(a != null){
    var b = a.getFiles(importVideoExtension);
    var c = b.length;
    for(var i = 0; i &lt; c; i++){
    imported[i] = importAFile(b[i]);
    imported[i].parentFolder = footage;
    }
    }

    function importAFile(fileObj){
    try{
    if((fileObj instanceof File) && ((fileObj.name.indexOf(".mp4") != -1) || (fileObj.name.indexOf(".mpg") != -1))){
    currImport = app.project.importFile(new ImportOptions(fileObj));
    return currImport;
    }else{
    return false;
    }
    }catch(e){}
    }

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