Skip to main content
StephaneLevy
Participant
March 31, 2022
Question

System command issue in an After Effects script - can't retrieve clean folder content

  • March 31, 2022
  • 1 reply
  • 128 views

I get strange results when using this kind of code in an After Effects script:

 

my_path = "Users/abc/def";
my_files = system.callSystem("cd " + my_path + " ; ls");

 

I then want to retrieve elements one by one, in an Array, but it seems that odd characters get in the way, and "hidden" items like indexes. I can get for instance 9 elements instead of 2.

I can get sth like this:

 

/bin/sh:,line,1:,2:,command,not,found,picture1.dng,movie1.mp4

 

What should I do to retrieve a clean list, which would only contain the folder items:

 

picture1.dng,movie1.mp4

 

This topic has been closed for replies.

1 reply

bretyboy
Inspiring
November 1, 2022

Hey there, 

You could get all files from your folder and then remove the hidden ones like this:

 

var yourFolderPath = "/Users/yourUserName/Desktop"
var searchThisFolder = Folder(yourFolderPath)
var listOfAllFiles = searchThisFolder.getFiles();

// You could remove hidden items if you want
var cleanFileList = []
for (var i = 0; i < listOfAllFiles.length; i++) {
    var curFile = listOfAllFiles[i];
    // skip hidden files
    if(curFile.hidden){
        continue;
    }
    cleanFileList.push(curFile)
}

alert("cleanFileList contains " + cleanFileList.length.toString() + " files (hidden files filtered out)")

 

 

Also a nice trick if you already know your file name, you could filter files like this:

var yourSearchPhrase = “search whatever file names you want here"
var searchThisFolder = Folder("your/Folder/Path")

var regthis = new RegExp(yourSearchPhrase);
var foundFileList = searchThisFolder.getFiles(regthis);

alert(foundFileList)