Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

getFiles() does not return the correct first file of the folder

New Here ,
Feb 20, 2020 Feb 20, 2020

Hi all,

 

I'm currently writing a script that imports and organises our image sequences correctly. Using After Effects 15.1 and Windows 10.

This includes getting the start and end frame of the sequence, which is added to our image names. This is the current naming convention: prj_shot.frame.ext

 

With the majority of the projects, the script correctly gets the correct frames ranges, but there are a few that strangely pick random frames as start and end frame.

The file names for the project are formatted the same.

 

Have no idea why would change behaviour for some projects!

 

Also, when iterating through the folder the strange projects only show the same file, instead of all of the different ones.

 

 

 

// Imports the files to AE
function importFileSeq(fileList, ext) {
    
    var mediaFile = new ImportOptions(fileList)
     mediaFile.importAs = ImportAsType.FOOTAGE
    
    if (ext != "mp4") {
        mediaFile.sequence = true
    }
    
    var seq = app.project.importFile(mediaFile)
    return seq
    
}

// Get the frame ranges for each shot/take for user information and frame counter
function getFrames(lst) {
    
    var startFilePath = lst[0].toString().split(".")
    var startFrameList = startFilePath[startFilePath.length - 2]
        
    startFrame = startFrameList.substr(startFrameList.length - 4)
    var endFilePath = lst.pop().toString().split(".")
    var endFrameList = endFilePath[endFilePath.length - 2]
    endFrame = endFrameList.substr(endFrameList.length - 4)

}

listPasses = shotFolder.getFiles()

for (var i = 0; i < listPasses.length; i++) {

    listFiles = listPasses[i].getFiles() <----- Issue
    seq = importFileSeq(listFiles[0])
    getFrames(listFiles)

}

 

 

 

As anyone experiences this before?

Does `getFiles()` not return files in alphabetic order?

 

Thank you very much in advance! 😊

 

Andre

TOPICS
Error or problem , Import and export , Scripting , SDK
673
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Feb 20, 2020 Feb 20, 2020

getFiles() does not guarantee you'll have a sorted alphabetical list. To fix this, simply sort those files like so:

var listFiles = listPasses[i].getFiles();
listFiles.sort(function(a, b) {
    return a.name > b.name;
});
Translate
Advocate ,
Feb 20, 2020 Feb 20, 2020

getFiles() does not guarantee you'll have a sorted alphabetical list. To fix this, simply sort those files like so:

var listFiles = listPasses[i].getFiles();
listFiles.sort(function(a, b) {
    return a.name > b.name;
});
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 20, 2020 Feb 20, 2020
LATEST

Hi Tomas,

 

Thank you so much for your quick and helpful reply!

Just tried it and works like a treat 😊

 

All the best!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines