Quantcast
Channel: Adobe Community : Popular Discussions - Photoshop Scripting
Viewing all articles
Browse latest Browse all 12244

Does file.rename() require the file to be open on apple platform?

$
0
0

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[i].fullName);

var f = files[i];

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');


Viewing all articles
Browse latest Browse all 12244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>