Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
May 23, 2014 May 23, 2014

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

TOPICS
Actions and scripting
316
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Guru ,
May 23, 2014 May 23, 2014

Rename takes the last part only… I didn't test but at a glance you are passing full path…?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 23, 2014 May 23, 2014

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
May 23, 2014 May 23, 2014
LATEST

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…?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines