cancel
Showing results for 
Search instead for 
Did you mean: 

List of files (including folders)

libman
Champ in-the-making
Champ in-the-making
Hi,

I would like to get the list of files of the space I'm in and change the first character of the file to capital, if not in capital.

For this, I am using a webscript, executed in inbound.

I know that I must use the ScriptNode copy(ScriptNode source, ScriptNode destination, String name) function to replace the name. This is not a problem. But to get the files and folders, I must use Lucene. But there, I see how to get a list of spaces, but for whole the repository. (TYPE:"{http://www.alfresco.org/model/content/1.0}folder")

Now, I would like to only get the files and folders from the directory I am on. I did not find a function for this. Space is described as following: "will be the space that the rule resides in, this may not be the space you are expecting if the rule is inherited. ", so not good.

Thanks.
6 REPLIES 6

libman
Champ in-the-making
Champ in-the-making
No one?

loftux
Star Contributor
Star Contributor
Here is how you can do it in freemarker
http://wiki.alfresco.com/wiki/Example_Recursive_Template

And this is a simple javascript I've used to loop the repo for conversion, I ran it from a Space, View Details, Run Action

if(space.isContainer)
{
   updateCorr(space);
}

function updateCorr(node)
{
   for each (n in node.children)
   {
      if(n.isDocument)
             {
         //DoSomeStuff
      }
      if(n.isContainer)
         updateCorr(n);
   }
}
This should get you going.

libman
Champ in-the-making
Champ in-the-making
I got the following error:

Failed to run Actions due to error: Failed to execute script 'workspace://SpacesStore/0ba91e52-4a33-45bc-bbda-43cf83d7f0b3': Failed to execute script 'workspace://SpacesStore/0ba91e52-4a33-45bc-bbda-43cf83d7f0b3': needed ';' before an instruction(AlfrescoScript#1)
(last line, beginning with: I translated myself, from French).

I executed the same manner as you described ( Run Action, on a space).

My code, which is exactly like yours:

if(space.isContainer)
{
   updateCorr(space);
}

function updateCorr(node)
{
   for each (n in node.children)
   {
      if(n.isDocument)
             {
         //DoSomeStuff
      }
      if(n.isContainer)
         updateCorr(n);
   }
}
Thanks very much or your answer.

kevinr
Star Contributor
Star Contributor
Do you mean get the children of the current folder and work out what are files (i.e. not containers such as folders) and then rename them?

If so that is easy:

var items = space.children;
for (var i=0; i<items.length; i++)
{
    if (items[i].isDocument)
    {
        // do some work, such as rename the file
        items[i].name = items[i].name + ".xyz";
        items[i].save();
    }
}

libman
Champ in-the-making
Champ in-the-making
Thanks, that is better, but what I wanted to say with my last comment, is that when executing the code (with details on a space, then run action->script->myscriptname->Finish) I got the error I wrote. Also, with your new code, I get the same error. I saved it as "generalisation.js".

Thanks very much!

libman
Champ in-the-making
Champ in-the-making
With the other default scripts (most of them), I get the following:
Failed to run Actions due to error: Failed to execute script 'workspace://SpacesStore/0cfd1f9d-a388-4d94-8e19-60203a8b4675': Failed to execute script 'workspace://SpacesStore/0cfd1f9d-a388-4d94-8e19-60203a8b4675': Wrapped org.alfresco.service.cmr.repository.CyclicChildRelationshipException: Cyclic parent-child relationship detected: current node: 4472 current path: {http://www.alfresco.org/model/system/1.0}henry.jones/{http://www.alfresco.org/model/content/1.0}Back... next assoc: 4490 (AlfrescoScript#11)
What can be the problem?