Hope this will help you, this code expects you to have a TEXT file with a list of filenaames that willl be used to sort the selected folder. N.B. The text file MUST have the names of the files in SAME case as on disk. Example: mypicture.jpg (in the text file ) is not the same as MyPicture.jpg on the disc. They must be the same! #target bridge if( BridgeTalk.appName == "bridge" ) { var sortWithTextFile = new MenuElement( "command","Sort on TXT file", "at the end of Tools" , "txtsort" ); } sortWithTextFile.onSelect = function () { var txtFile = File.openDialog("Please select TEXT file.","TXT File:*.txt"); if(txtFile == null) return; var fileNames = new Array(); txtFile.open('r'); while(!txtFile.eof){ var line = txtFile.readln(); if(line.length <4) continue; fileNames.push(line.toString().replace(/^[\s]+|[\s]+$/g, '')); } txtFile.close(); var fileSort = new File(app.document.presentationPath +"/.BridgeSort"); var fileNames2 = new Array(); if(fileSort.exists) fileSort.remove(); var fileList=[]; for(var f in fileNames){ var tmpFile = File(app.document.presentationPath + "/" + fileNames .toString()); if(!tmpFile.exists) continue; //Ignore files that do not exist, better to create an error file. fD = File(tmpFile).created; var FileDate = fD.getFullYear() + (zeroPad(fD.getMonth() +1,2).toString()); FileDate += (zeroPad(fD.getDate(),2).toString()) + (zeroPad(fD.getHours(),2).toString()); FileDate += (zeroPad(fD.getMinutes(),2).toString()) + (zeroPad(fD.getSeconds(),2).toString()); fileList.push([[decodeURI(tmpFile.name)],[FileDate]]); } app.document.sorts = [{ type:"string",name:"name", reverse:false }]; fileSort.open("w", "TEXT", "????"); fileSort.lineFeed="Unix"; fileSort.encoding = "UTF-8"; fileSort.writeln("<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>"); fileSort.writeln("<dirinfo>"); fileSort.writeln("<files>"); for(var t in fileList){ fileSort.writeln("<item key='" +fileList [0].toString().replace(/&/,"&") +fileList [1].toString() +"' />"); } fileSort.writeln("</files>"); fileSort.writeln("</dirinfo>"); fileSort.close(); fileSort.hidden=true; app.document.chooseMenuItem("mondo/command/new"); app.documents[0].close(); app.document.sorts = [{ name:"user",type:"date", reverse:false }]; function zeroPad(n, s) { n = n.toString(); while (n.length < s) n = '0' + n; return n; }; };
... View more