What's new
Photoshop Gurus Forum

Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Reply to thread

Ah! Sorry, I was under the impression that the filenames were the same but the 'tif' filename only contains the psd filename...right?


If that's the case then this should fix it:


[CODE=jsx]// Prompt user to select Source and Destination folders

var sourceFolder = Folder.selectDialog("Select Source Folder");

var destFolder = Folder.selectDialog("Select Destination Folder");


if (sourceFolder && destFolder) {

var sourceFiles = sourceFolder.getFiles("*.psd");

var destFiles = destFolder.getFiles("*.tif");


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

var sourceFile = new File(sourceFiles);                                                                    // ** EDITED **

var sourceFileName = sourceFile.name.replace(/\.[^.]+$/, ""); // Remove extension


for (var j = 0; j < destFiles.length; j++) {

var destFile = destFiles[j];

var destFileName = destFile.name.replace(/\.[^.]+$/, ""); // Remove extension


if (destFileName.indexOf(sourceFileName) !== -1) {

var sourceDoc = app.open(sourceFile);            

var destDoc = app.open(destFile);        


// Duplicate the background layer from destination

var destBackgroundLayer = destDoc.artLayers[0];                                                              // ** BLOCK MOVED TO BEFORE 'DELETE LAYER 1' **

var sourceLayer = destBackgroundLayer.duplicate(sourceDoc, ElementPlacement.PLACEATBEGINNING);

app.activeDocument = sourceDoc;                                                                             // ** ADDED **


// Delete Layer 1 in source document

if (sourceDoc.layers.length > 0) {                                                                          // ** BLOCK MOVED TO AFTER 'DUPLICATE LAYER' **

sourceDoc.layers[sourceDoc.layers.length - 1].remove();

}


// Loop through layers in source document

for (var k = sourceDoc.layers.length - 1; k >= 0; k--) {

var sourceChildLayer = sourceDoc.layers[k];

var sourceParentLayer = sourceChildLayer.parent;


// Check if the source layer is a clipping mask

if (sourceChildLayer.grouped && sourceParentLayer) {

// Find the corresponding parent layer in destination

var destParentLayerName = sourceParentLayer.name;

var destParentLayer = destDoc.layers.getByName(destParentLayerName);


if (destParentLayer) {

sourceChildLayer.duplicate(destParentLayer, ElementPlacement.PLACEATBEGINNING);

}

}

}


// Save modified source file in destination folder with PSD file name

var newFileName = destFileName + "_modified.psd";                                                // ** CHANGED 'sourceFileName' TO 'destFileName'  **

var saveName = new File(decodeURI(destFolder + "/" + newFileName));                            // ** EDITED **

sourceDoc.saveAs(saveName);                                                                     // ** EDITED **


sourceDoc.close(SaveOptions.DONOTSAVECHANGES);

destDoc.close(SaveOptions.DONOTSAVECHANGES);


// break; // Once matched, move to the next source file                                       // ** NOT REQUIRED **

}

}

}

} else {

alert("Please select both Source and Destination folders.");

}[/CODE]


Sorry for the missunderstanding.


Regards.

MrToM.


What is our favorite program/app? (Hint - it begins and ends with the letter P)
Back
Top