检查 JMP Live 空间中是否存在文件夹你好,
使用 JMP18 中的 JSL,我可以使用“创建文件夹”功能在我的个人空间和 JMP Live 上的其他空间中创建新文件夹。当我在个人空间中创建文件夹时,我可以使用 JSL 的“查找文件夹”功能首先列出所有现有文件夹,然后检查我的新文件夹是否已存在。然后我可以通过 JSL 确保文件夹名称唯一。
JMP Live 的默认行为是通过在文件夹名称中添加“ (n) ”来创建唯一的文件夹名称,其中“ n ”表示具有相同名称的文件夹数量。但我想避免这种情况。
在其他 JMP Live 空间(不是我的个人空间)中,我观察到了相同的行为:相同的文件夹名称会自动附加“ (n) ”。但是,“查找文件夹”功能没有 Space Key 作为参数,因此我无法检查非个人空间中是否存在现有文件夹。
我发现唯一接受空格键作为参数的函数是“创建文件夹”函数。我查看了此处相关的 JSL 帮助页面,但没有描述这种情况。
推荐的提取 JMP Live 空间中现有文件夹的方法是什么?还是我在这里忽略了显而易见的东西?
谢谢!
保罗
自动化和脚本回复:检查 JMP Live 空间中是否存在文件夹我不熟悉 JMP Live,但您是否尝试过增加查询的页面大小(或利用 Next() 调用)?脚本索引可以有一些您在 JMP 帮助页面中找不到的示例

回复:检查 JMP Live 空间中是否存在文件夹谢谢 Jarmo,
不,我还没有尝试过。这是我的代码,可以很好地检查个人空间中现有的文件夹。
没有包含确保唯一文件夹名称的代码(为了简单起见),但可以轻松创建。
正如我在帖子中所述: “查找文件夹”功能似乎没有空格键,并且默认在我的个人 JMP Live 空间中运行查询。
我猜测FindFolders中的 PageSize 参数可用于翻阅一长串文件夹列表(如果它们存在的话)。
// open the connection to JMP Live
liveConnection = New JMP Live( Connection( ) );
// get the user name from JMP Live
user = liveConnection << Get Username;
// get the existing folders already in my Space
getFolders = liveConnection << Find Folders( Publisher( user ) );
folderlist = getFolders << As Scriptable();
// Define the folder name you want to check or create
folderName = "new_folder_name";
// Define the space key of the Space you wish to create the folder in
spaceKey = "~"; // set key to "~" for your personal space or use the space key
// Initialize a variable to store the folder ID
folderID = .;
// Check if the folder exists. If it exists, folderID will contain the ID
// if the folder does not exist, folderID will contain a missing value
For( i = 1, i <= folderlist << Get Number Of Items, i += 1,
If( folderlist[i] << Get Title == folderName,
folderID = folderlist[i] << Get ID;
Show( folderID );
Break();
)
);
// If the folder does not exist, create it. folderID will contain the folder ID.
If( Is Missing( folderID ),
newFolder = liveConnection << Create Folder(
Space( spaceKey ), // Use "~" for personal space or specify the space key
Title( folderName ),
Description( "Automatically created folder." )
);
folderID = newFolder << As Scriptable;
folderID = folderID << Get ID;
);
回复:检查 JMP Live 空间中是否存在文件夹还有一条评论,如果我运行“查找文件夹”功能并手动检查返回的列表,我可以看到我的个人空间中每个文件夹都有一个列表条目。没有其他条目(而我可以访问其他带有文件夹的空间)。
保罗
回复:检查 JMP Live 空间中是否存在文件夹您是否尝试从“查找文件夹”中删除此部分
Publisher( user )
回复:检查 JMP Live 空间中是否存在文件夹嗨,贾莫,
谢谢你的建议。结果它成功了!
此代码(将搜索函数作为参数添加到“查找文件夹”函数):
// open the connection to JMP Live
liveConnection = OpenJMPLiveConnection( );
foldername = "foldername";
// get the existing folders already in my Space
getFolders = liveConnection << Find Folders( Search( foldername ) );
folderlist = getFolders << As Scriptable();
Show(folderlist);
如果文件夹存在于我的个人空间之外,则返回文件夹的名称、描述、ID 和 URL。
保罗