Copy link to clipboard
Copied
The Following is for users to be able to pick a csv file , and rename images in a directory based on contents in the csv.
But file.rename() fails on apple platform but on windows it works without files open.
var textFile = File.openDialog ("Open Data Excel Sheet", "*.txt,*.csv",false);
var imageDir = Folder.selectDialog("Select Source Directory");
var destinationDir = Folder.selectDialog("Select Destination");
var line = 0;
var articleColumn = 7;
var upcColumn= 9;
var filetype = "*.tif";
var upctoart = [];
if(textFile != null && imageDir != null && destinationDir != null){
textFile.open('r');
while(!textFile.eof)
{
var row = textFile.readln();
var cols = row.split("\t");
upctoart[cols[upcColumn]]=cols[articleColumn];
line++;
}
textFile.close();
var files = imageDir.getFiles(filetype);
for(var i = 0; i < files.length; i++)
{
//alert (files.fullName);
var f = files;
var fileName = f.name;
var fs = fileName.split("_");
if(typeof upctoart[fs[0]] == 'undefined')
{
continue;
}
var artNum = upctoart[fs[0]];
var destinationFileName = fileName.replace(fs[0],artNum);
f.rename(destinationDir.fsName + '/' + destinationFileName);
}
}
alert('Done');
Copy link to clipboard
Copied
Rename takes the last part only… I didn't test but at a glance you are passing full path…?
Copy link to clipboard
Copied
That still means there a difference between apple / windows platform for the javascript. I will test just the filename local not moving the file not my preferred option.
I want the destination changed as well. Which is why I'm giving the full path.
Copy link to clipboard
Copied
Then I thinks you have selected the wrong file object method… Try using copy… ( this will create a NEW at location ).
Rename just replaces the last component of the URI string nothing more… ExtendScript has no MOVE file… So copy and remove is your option…?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now