Question
script to rename files from a csv document
I'm trying to organize files by a certain date, i have all the dates in a csv file, but i need to write the script to rename the undated files. they are in the exact order on the csv to combine with the order on bridge. just need to know how to connect the two
- #target bridge
- if( BridgeTalk.appName == "bridge" ) {
- fileNameToProduct = MenuElement.create("command", "Rename to Product", "at the end of Thumbnail");
- }
- fileNameToProduct.onSelect = function () {
- renameToProduct();
- }
- function renameToProduct(){
- var Path =app.document.presentationPath;
- var descFile = File.openDialog("Open Product File","CSV File(*.csv):*.csv;");
- if(descFile == null) return;
- descFile.open('r');
- var datFile=[];
- while(!descFile.eof){
- var line = descFile.readln();
- if(line.length > 5) datFile.push(line);
- }
- descFile.close();
- for(var t in datFile){
- var str=datFile
; - str= str.split(',');
- var fileName = File(Path+"/"+ str.shift());
- var product = str.shift();
- if(!fileName.exists) continue;
- var ext = fileName.toString().toLowerCase().match(/[^\.]+$/);
- var thumb = new Thumbnail(fileName);
- var md = thumb.synchronousMetadata;
- md.namespace = "http://ns.adobe.com/xap/1.0/mm/";
- md.PreservedFileName = thumb.name;
- $.sleep(100); //give it time to update the metadata
- var newName = product + "." +ext;
- fileName.rename(newName);
- }
- alert("All done");
- }
I've tried this script and it didn't work.
