Hi, I have this script below that read from CSV and then copy picture liste to another folder. Everything seems to work right when I have 10 pictures in my csv file. When I have more than 10 pictures in my csv file. Photoshop hang and freeze, I have to close it. It does the same on PC and MAC. Any help would be great, I tried everything
tks
Seby
Here's the csv file that I'm trying to use. If you remove like 6 lines of pictures, the script work to the end.
http://www.sebyphotographe.com/csv.csv
Code: Select all function main() {
var csvFile = File.openDialog("Open The CSV","comma-delimited(*.csv):*.csv;");
datafile = new File(csvFile);
var csvString = [];
var header = '';
var headerarray= [];
if (datafile.exists){
datafile.open('r') ;
var t=0;
while(!datafile.eof){// read one line at a time until end of file
if (t==0) header=datafile.readln().replace(/^\s+|\s+$/g, '');
else{
var line=datafile.readln().replace(/^\s+|\s+$/g, '');
if (line.length) csvString.push(line);
}
t=1;
}
datafile.close();
}
var searchFolder = Folder.selectDialog ("Select The pictures folder")
var saveFolder = Folder.selectDialog ("Where Do You Want To Save Them?")
for(var l =0;l<csvString.length;l++){
var toFind2=csvString[l].split('\t');
headerarray=header.split('\t');
for(var l =2;l<headerarray.length;l++){
var myfolder=new Folder(saveFolder.fullName+"/"+toFind2[0]+"/"+headerarray[l]);
if (!(myfolder.created)) myfolder.create();
}
}
getListOfFiles(searchFolder);
var cnt=0;
for(var l =0;l<csvString.length;l++){
var toFind=csvString[l].split('\t');
for(var i=0;i<searchFiles.length;i++){
var m = toFind[1].toLowerCase();
if (m)
if(decodeURI(searchFiles.name).toLowerCase() == decodeURI(m)){
for(var h =2;h<headerarray.length;h++){
if (toFind[h])
for (var d=0;d<toFind[h];d++){
var ran=randomString(3);
var ext =searchFiles.name.substring (searchFiles.name.lastIndexOf ('.'));
toFind[1]=toFind[1].replace(ext,'');
var newFilepath = saveFolder.fullName+"/"+toFind2[0]+"/"+headerarray[h]+"/"+toFind[1]+'(x'+toFind[h]+')_'+ext;
if( saveFolder.exists && searchFiles instanceof File){
var newFile = new File(newFilepath);
searchFiles.copy(newFile);
cnt++;
}
}
}
}
}
}
alert('Copied '+cnt+' files');
};
searchFiles=[];
main();
function getListOfFiles(folder) {
var fileList = folder.getFiles();
for (var i = 0; i < fileList.length; i++) {
var file = fileList;
if (file instanceof File) searchFiles.push(file);
if (file instanceof Folder) getListOfFiles(file);
}
}
function randomString(length) {
var chars = '0123456789abcdefghijklmnopqrstuvwxyz';
var result = '';
for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];
return result;
}