script
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2012 01:33 PM
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
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
Labels:
- Labels:
-
Archive
4 REPLIES 4
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2012 06:57 PM
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.
Jeff
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 wantvar oldName = doc.properties.name;var newName = oldName.replace('.bin', '.pdf');doc.properties.name = newName;doc.save();
Jeff
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2012 05:08 AM
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
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2012 05:57 AM
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".
You may want to look at doing a "rendition" rather than a "transformation".
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2013 10:50 AM
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?
Is there a file where I can modify that?
