2 Replies Latest reply on May 23, 2014 10:00 AM by knoseworthy

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

    knoseworthy

      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.

       

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