Copy link to clipboard
Copied
Greetings to all!
Is there a script that can check if a folder does not contain any files?
Folder('~/desktop').getFiles().length
Copy link to clipboard
Copied
Folder('~/desktop').getFiles().length
Copy link to clipboard
Copied
fileExist = Folder("~/desktop/"); fileList = fileExist.getFiles();
if(fileList.length == 0){ alert ("Empty folder");} else{ alert ("Non-empty folder"); }
Copy link to clipboard
Copied
Thank you all for the beautiful support!
Copy link to clipboard
Copied
Why you're giving the same answer I did 5 hours earlier?
Copy link to clipboard
Copied
Adding to the reply from Kukurykus:
var howMany = Folder('~/desktop').getFiles().length;
alert(howMany + ' items found');
It is worth keeping in mind that this will return all files and folders/directories. You may not want to count the folders. Also, just because a file is found, does not mean that it can be processed by Photoshop.
It depends on how robust and for what purposes this is being used.
The same applies to the reply from Shulipa Bernad:
var fileExist = Folder("~/desktop/");
var fileList = fileExist.getFiles();
if (fileList.length === 0) {
alert("Empty folder");
} else {
alert("The folder " + "'" + fileExist + "'" + " contains " + fileList.length + " items.");
}
To limit the file input, one can do something like this:
var fileExist = Folder("~/desktop/");
// Limit file format input & exclude folders from count
var fileList = fileExist.getFiles(/\.(jpg|jpeg|tif|tiff|png|psd)$/i);
if (fileList.length === 0) {
alert("Empty folder");
} else {
alert("The folder " + "'" + fileExist + "'" + " contains " + fileList.length + " items.");
}
Note: This is not intended as negative critisism, I'm just stating the facts, it all depends on how the code is used.