Yes, that's about it Stephen. If you look at my original post, I included a spreadsheet that had a folder structure that showed basicly how things are layed out. By using what you have provided, I was hoping to be able to read the file name from Excel and use it to hone in on the correct folder. Then I would pull the file from that folder to, as you said, a desktop folder for example. I would have to write something into the code to bypass a file that was not found/unavailable. I already have a script I wrote about 12 years ago with the help of Mike Hale, R.I.P., that asks the user for CSV location, Source and destination folders. It then grabs the files, renames them to Column B and saves them. I was hoping to somehow use it as the base to build upon. Only thing is, I would need to read the CSV and THEN determine each individual source folder based upon the SKU number read. The whole looping thing does my head in. Here is the Find, Rename and Save script. function main() {
var csvFile = File.openDialog("Open Comma-delimited File","comma-delimited(*.csv):*.csv;");
datafile = new File(csvFile);
var csvString = [];
if (datafile.exists){
datafile.open('r') ;
while(!datafile.eof){// read one line at a time until end of file
csvString.push( datafile.readln().replace(/^\s+|\s+$/g, '') );
}
datafile.close();
}
var searchFolder = Folder.selectDialog ("Select folder to search in")
var saveFolder = Folder.selectDialog ("Select folder to save files")
getListOfFiles(searchFolder);
for(var l =0;l<csvString.length;l++){
var toFind=csvString[l].split(',');
for(var i=0;i<searchFiles.length;i++){
var m = toFind[0].toLowerCase();
if(decodeURI(searchFiles[i].name).toLowerCase() == decodeURI(m)){
var ext =searchFiles[i].name.substring (searchFiles[i].name.lastIndexOf ('.'));
var newFilepath = saveFolder.fullName+"/"+toFind[1]+ext;
if( saveFolder.exists && searchFiles[i] instanceof File){
var newFile = new File(newFilepath);
searchFiles[i].copy(newFile);
}
}
}
}
};
searchFiles=[];
main();
function getListOfFiles(folder) {
var fileList = folder.getFiles();
for (var i = 0; i < fileList.length; i++) {
var file = fileList[i];
if (file instanceof File) searchFiles.push(file);
if (file instanceof Folder) getListOfFiles(file);
}
}
... View more