cancel
Showing results for 
Search instead for 
Did you mean: 

script

edwardlobo
Champ in-the-making
Champ in-the-making
I am trying to create a script to rename all files in a space. The file extension is filename.bin

I want to rename it to filename.pdf without doing any other process on the file

So far I have tried the following script but without any luck
————–
// change the name of this document
  document.properties.name = document.properties.name+".pdf";
  // add a new property string
  document.properties["cm:locale"] = mylocalenode;
  // save the property modifications
  document.save();
—————-

any help to correct would be appreciated
4 REPLIES 4

jpotts
World-Class Innovator
World-Class Innovator
I have answered this on stackoverflow as well. Going forward, please ask questions here or there but not both…

The script as written would take a document named "filename.bin" and rename it to "filename.bin.pdf". It would then set a property called "cm:locale" equal to the value of mylocalenode, which appears to be undefined in this snippet. I don't know what you are going for with the cm:locale so I will ignore that and give you a script that will search for the document named filename.bin and change its name.

If you would rather iterate over the children in a folder, you should be able to look at the Alfresco JavaScript API to figure out how to modify the snippet below to do that.

var results = search.luceneSearch("@cm\\:name:filename.bin");
var doc = results[0]; // assumes there is only one result, which may not be what you want
var oldName = doc.properties.name;
var newName = oldName.replace('.bin', '.pdf');
doc.properties.name = newName;
doc.save();

Jeff

edwardlobo
Champ in-the-making
Champ in-the-making
Many thanks Jeff

I was trying to do scanned pdf to image pdf however because transformation only works from one file type to another I used the ocr utility to scan pdf into a pdf but with bin extension.

I then wanted to just change the filename to .pdf by either using a bin to pdf transformation with ren or via a java script as a rule once a *.bin file lands into a folder.

I created the script you gave me and created a rule saying when the filename contains *.bin execute the script. Is there any other step I missed

mrogers
Star Contributor
Star Contributor
Yes.  Please note that transformation is done on mime type, not file name.     Changing the name of a file will not / should not change the mimetype.

You may want to look at doing a "rendition" rather than a "transformation".

thomasbzh
Champ in-the-making
Champ in-the-making
I have almost the same problem. I don't want to change these .bin but I would like to move them in the same file, directly in the contentstore.
Is there a file where I can modify that?