重命名Alfresco脚本中的文件

Renaming files in an Alfresco script

本文关键字:文件 脚本 Alfresco 重命名      更新时间:2024-02-12

我很难在Alfresco中编写一个脚本来重命名文件扩展名。

该文件保存为filename.bin。我使用内容规则来说明当filename等于*bin时重命名为*pdf

我在剧本上有点吃力,如果有任何帮助,我将不胜感激。

我的脚本如下:

// 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();

但似乎没有给我任何帮助。

编写的脚本将获取一个名为"filename.bin"的文档,并将其重命名为"filename]bin.pdf"。然后,它将设置一个称为"cm:locale"的属性,该属性似乎为此代码段中未定义。我不知道您使用cm:locale的目的是什么,所以我将忽略它,并给您一个脚本,该脚本将搜索名为filename.bin的文档并更改其名称。

如果您更愿意迭代文件夹中的子项,那么您应该能够查看Alfresco JavaScript API,以了解如何修改下面的代码段来实现这一点。

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();

添加更多内容,因为您使用的是content-rule。不需要使用lucene/solr服务搜索文档。我们可以直接访问文档对象,它指的是正在执行规则的文档。

因此,代码如下所示。

var oldName = document.properties.name;
var newName = oldName.replace('.bin', '.pdf');
document.properties.name = newName;
document.save();