This variation on my previous code will use native Mac/Win operating system commands to move the files (rather than copy and delete).
/*
THIS SCRIPT HAS NO GUARANTEE OR WARRANTY - USE AT YOUR OWN RISK!
*/
#target photoshop
if (confirm("Do you wish to move all files with no clipping paths to a new folder?")) {
var folder = Folder.selectDialog("Select the folder with images");
if (folder) {
var files = folder.getFiles(/\.(psd|psb|tif|tiff|jpg|jpeg)$/i); // Adjust file types as needed
for (var i = 0; i < files.length; i++) {
var file = files[i];
open(file);
var doc = app.activeDocument;
var hasClippingPath = false;
// Check if there is any path in the Paths palette
if (doc.pathItems.length > 0) {
for (var j = 0; j < doc.pathItems.length; j++) {
if (doc.pathItems[j].kind == PathKind.CLIPPINGPATH) {
hasClippingPath = true;
break;
}
}
}
// If the open file has no clipping path
if (!hasClippingPath) {
// Create new folder named "No Clipping Paths" in the path of the open image
var noClipPathFolder = new Folder(file.parent + "/No Clipping Paths");
if (!noClipPathFolder.exists) {
noClipPathFolder.create();
}
// Move the file to the new folder
moveFile(file.fsName, noClipPathFolder + "/" + file.name);
}
doc.close(SaveOptions.DONOTSAVECHANGES);
}
app.beep();
alert("Script completed!");
}
}
function moveFile(from, to) {
// With special thanks to William Campbell - willcampbell7
// https://community.adobe.com/t5/photoshop-ecosystem-discussions/to-move-files-and-folders/td-p/8787869/page/3
// from = String: full path and name of file to move.
// to = String: full path and name of new file at destination.
var command;
var fileFrom;
var fileTo;
var folderTo;
fileFrom = new File(new File(from).fsName);
fileTo = new File(new File(to).fsName);
if (/%(?!20|5C)/.test(File.encode(fileFrom.fsName))) {
// Unicode characters detected in filename. Move will fail because
// ExtendScript cannot pass Unicode text to command prompt via a string variable.
return false;
}
if (!fileTo.exists) {
folderTo = new Folder(fileTo.path);
if (!folderTo.exists) {
folderTo.create();
}
if (File.fs == "Windows") {
command = "move \"" + fileFrom.fsName + "\" \"" + fileTo.fsName + "\"";
app.system(command);
} else if (File.fs == "Macintosh") {
command = "mv \"" + fileFrom.fsName + "\" \"" + fileTo.fsName + "\"";
app.system(command);
}
if (fileTo.exists) {
return true;
}
}
// Failed to move.
return false;
}
This final variation simply logs the file paths and names to a text file, it doesn't move them.
/*
Log files with no clipping path to text file
*/
#target photoshop
var folder = Folder.selectDialog("Select the folder with images");
if (folder) {
var files = folder.getFiles(/\.(psd|psb|tif|tiff|jpg|jpeg)$/i); // Adjust file types as needed
var logFile = new File(folder + "/no_clipping_paths_log.txt");
logFile.open("w");
logFile.writeln("Files with no clipping paths:\n");
logFile.close();
for (var i = 0; i < files.length; i++) {
var file = files[i];
open(file);
var doc = app.activeDocument;
var hasClippingPath = false;
// Check if there is any path in the Paths palette
if (doc.pathItems.length > 0) {
for (var j = 0; j < doc.pathItems.length; j++) {
if (doc.pathItems[j].kind == PathKind.CLIPPINGPATH) {
hasClippingPath = true;
break;
}
}
}
// If the open file has no clipping path
if (!hasClippingPath) {
// Log the file
logToFile(logFile, file.fsName + "\n");
}
doc.close(SaveOptions.DONOTSAVECHANGES);
}
}
// End of script notification
app.beep();
alert("Logging completed. Check the file: " + logFile.fsName);
// Open the text file
logFile.execute();
function logToFile(logFile, text) {
logFile.open("a");
logFile.writeln(text);
logFile.close();
}