【问题标题】:Check if folder exists检查文件夹是否存在
【发布时间】:2018-01-04 16:22:09
【问题描述】:
我的结构如下
MyRootFolder
└──subfolder1
└──subfolder2
.
.
.
└──subfolder n
我有一个要求,我需要检查根文件夹中是否存在子文件夹,如果不存在则创建它。我找不到直接 API 来检查子文件夹是否存在。相反,我看到了类似的 API
folder.get_SubFolders();
这会给我一个所有子文件夹的列表,然后迭代检查子文件夹是否存在。这里的问题是我最终可能不得不迭代许多我不想做的文件夹。有没有不同的方法来实现这一目标?我正在使用 Filenet 5.2.1
【问题讨论】:
标签:
filenet-p8
filenet
filenet-content-engine
【解决方案1】:
好的,这是我能找到的最接近的选项。
使用以下查询在 FileNet 中搜索子文件夹。
SELECT FolderName FROM Folder WHERE FolderName='subfolder1' and Parent=OBJECT({parent-folder-guid})
如果上述搜索返回结果,则如果没有创建子文件夹,则存在子文件夹。
【解决方案2】:
另一种方法可能是 - 你尝试创建一个你想要的文件夹,如果已经存在,不要创建它,否则创建它。要实现它,您不必遍历现有文件夹。我对我的一个项目有相同的要求,我必须将内容从共享驱动器移动到 FileNet P8 并为它们分配属性,同时保持相同的文件夹路径。关注 sn-p 可能会对某人有所帮助:
public static Folder createFolderStructure() {
Connection conn = Factory.Connection.getConnection(ConfigInfo.CE_URI);
Domain dom = Factory.Domain.getInstance(conn, null);
ObjectStore os = Factory.ObjectStore.getInstance(dom,
ConfigInfo.OBJECT_STORE_NAME);
Folder folder = null;
// pass your desired folder string here, excluding the starting root "/"
String folderpath = "APITest/some/folder/2014/12/2";
System.out.println("\nGiven input folder path is :: " + folderpath + "\n");
String[] myarray = folderpath.split("/");
for (int x = 0; x < myarray.length; x++) {
try {
if (x == 0) {
folder = Factory.Folder.createInstance(os, null);
Folder rootFolder = Factory.Folder.getInstance(os, null, "/");
folder.set_Parent(rootFolder);
folder.set_FolderName(myarray[x]);
System.out.println("Creating main (first) folder.. \t" + myarray[x]);
folder.save(RefreshMode.NO_REFRESH);
} else {
String currentfolder = myarray[x];
String parentfolder = "";
for (int i = 0; i < x; i++) {
folder = Factory.Folder.createInstance(os, null);
parentfolder = parentfolder + "/" + myarray[i];
Folder nxtrootFolder = Factory.Folder.getInstance(os, null, parentfolder);
folder.set_Parent(nxtrootFolder);
folder.set_FolderName(currentfolder);
}
System.out
.println("Trying to create " + currentfolder + " in " + parentfolder);
folder.save(RefreshMode.NO_REFRESH);
}
} catch (EngineRuntimeException ere) {
ExceptionCode code = ere.getExceptionCode();
if (code != ExceptionCode.E_NOT_UNIQUE) {
throw ere;
}
System.out.println("Above folder already exists...skipping...");
}
}
return folder;
}
这是从我自己的blog复制过来的。