Hi, I use that script below for copying photos from one folder to another folder based on the count in a csv. But, I need a third option to copy then, I would like to copy the file but with the quantity and the format a the end of the name that you can find in the csv. Now I have the option to retouching wich is just copying all the files into a retouching folder. Then I have the second option to copy all the files times the quantity in their format folder. And the third option need to copy them also one time in their format folder, but adding to the filename the quantity and the format in the name itsef. See at the end what I mean exactly.
Code: Select all function main() {
var csvFile = File.openDialog("Open Comma-delimited File","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 folder to search in")
var saveFolder = Folder.selectDialog ("Select folder to save files")
headerarray=header.split('\t');
for(var l =2;l<headerarray.length;l++){
var myfolder=new Folder(saveFolder.fullName+"/"+headerarray[l]);
if (!(myfolder.created)) myfolder.create();
}
getListOfFiles(searchFolder);
var rt=confirm('Retouching? \n Click \'Yes\' for retouching or \'No\' if preparing for lab');
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)){
if (rt){
var myfolder=new Folder(saveFolder.fullName+"/"+'Retouching');
if (!(myfolder.created)) myfolder.create();
var ext =searchFiles.name.substring (searchFiles.name.lastIndexOf ('.'));
toFind[1]=toFind[1].replace(ext,'');
var newFilepath = saveFolder.fullName+"/"+'Retouching'+"/"+toFind[1]+ext;
if( saveFolder.exists && searchFiles instanceof File){
var newFile = new File(newFilepath);
if (newFile.exists){
alert('Duplicate photos found \n Action canceled');
return;
}
searchFiles.copy(newFile);
cnt++;
}
}
else{
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+"/"+headerarray[h]+"/"+toFind[1]+'-'+cnt+ran+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 = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
var result = '';
for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];
return result;
}
This is the format of the csv used
http://www.simplestudiophoto.com/mike.csv
So as you can see, I have the names and the quantity and the size of the pictures. So when they get copied in their folder, how to say that in the name of the file like
IMG_3904-4X6-2.jpg So I need 2 copies in 4X6 format.
tks for your help guys
Seby
Help on this Counting, copying And renaming file from csv
-
seby20
Help on this Counting, copying And renaming file from csv
Hi again, nobody can help me on that one?
tks
Seby
tks
Seby