ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

import files with getFiles - multiple extensions/file types

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Goran Hanzek
import files with getFiles - multiple extensions/file types
on Nov 4, 2019 at 10:22:20 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 &lt; c; i++){
imported[i] = importAFile(b[i]);
imported[i].parentFolder = footage;
}
}


Return to posts index

Scott McGee
Re: import files with getFiles - multiple extensions/file types
on Nov 4, 2019 at 1:36:52 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]));
}


Return to posts index

Goran Hanzek
Re: import files with getFiles - multiple extensions/file types
on Nov 5, 2019 at 2:12:04 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){}
}


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]