cancel
Showing results for 
Search instead for 
Did you mean: 

Removing files

ltardioli
Champ in-the-making
Champ in-the-making
Hello ppl,

I want to write a simple script thats remove all documents thats enter in a folder who doesnt has a extension ".backup".

var name = document.name;
var splited = name.split(".");
var index = splited.length;
if(splited[index -1]!="backup")
{
   document.remove();
}

I created a rule to execute this script but, every document is removed, even those who has the extension .backup.

Any ideas??

Thanks!
4 REPLIES 4

jpotts
World-Class Innovator
World-Class Innovator
My first thought is that you could write this more succinctly by using something like:
if (name.indexOf('.backup') < 0)

With that said, what you have seems like it should work. However, there is no need to put the name matching logic in the JavaScript unless you just want to. The rule configuration includes a filter by name which can be negated with a checkbox.

Jeff

ltardioli
Champ in-the-making
Champ in-the-making
Thanks for the tip!

I'm new in Javascript programming and I'm doing this examples to studying.
And your example worked fine.

jpotts
World-Class Innovator
World-Class Innovator
Excellent. Glad that worked!

If you have not already found and installed the JavaScript Console, I would encourage you to do so. It gives you a nice interactive way to run JavaScript against Alfresco directly in the Alfresco Share UI.

Another little trick is that you can run an interactive rhino shell on your desktop, like this:
java -classpath /opt/alfresco/4.0d-community/sdk/lib/server/dependencies/rhino-js-1.6R7.jar org.mozilla.javascript.tools.shell.Main

I put that in a file called "rhino.sh" and then whenever I can't remember some piece of JavaScript syntax or I just want to try a couple of things, I run that script and type away. Unlike the Share-based JavaScript console referenced above, this shell doesn't have direct access to the Alfresco API, but it is good for playing with straight JavaScript.

Jeff

ltardioli
Champ in-the-making
Champ in-the-making
I'm using JavaScript console and it is a great tool! Have helped me alot!

That rhino shell I didn't know it, but I'll try here!
Thanks for the help!