在DigitalMicrograph脚本中从文件夹打开多个文件 [英] Opening multiple files from folder in DigitalMicrograph scripting

查看:240
本文介绍了在DigitalMicrograph脚本中从文件夹打开多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我知道如何使用<$打开一个图像。

我试图写一个DigitalMicrograph脚本,打开包含文件名中的特定字符串的所有图像。 c $ c> OpenImage(filename),我在文档中看到一个命令 GetFilesInDirectory()存在,这似乎是我需要的。但是,我不明白我如何使用这个命令。有人可以给我一个代码片段来证明这一点,请解释一下吗?

解决方案命令 GetFilesInDirectory() code>给你一个给定目录中所有文件/子文件夹的TagList。这在以下示例中显示:

 字符串文件夹
TagGroup FileList
数字fFiles = 1
number fFolders = 2
$ b $如果(!GetDirectoryDialog(Select base folder,,folder))
Exit(0)

FileList = GetFilesInDirectory (文件夹,fFiles + fFolders)

如果(FileList.TagGroupCountTags()> 0)
FileList.TagGroupOpenBrowserWindow(Files& Folders,0)

这个脚本会在下面的浏览器窗口中显示最终的TagGroup。每个列表条目本身就是一个包含单个标签名称的标签组。该标签包含文件或文件夹名称。你可以使用这个命令来给你只有文件,只有子文件夹,或者两者都有。





  number nTags对于(数字I = 0; I  {
TagGroup entryTG
FileList.TagGroupCountTags()

FileList.TagGroupGetIndexedTagAsTagGroup(i,entryTG)$ b $ (entryTG.TagGroupIsValid())
{
字符串filestr
if(entryTG.TagGroupGetTagAsString(Name,filestr))
{
Result(\\ b \\ n文件:+ filestr)
}
}
}


I am trying to write a DigitalMicrograph script which opens all images containing a specific string in the file name.

I know how I can open an image using OpenImage( filename ) and I have seen in the documentation that a command GetFilesInDirectory() exists, which seems to be what I need. However, I do not understand how I can use this command. Can somebody give me a code snippet demonstrating this, please?

解决方案

The command GetFilesInDirectory() gives you a TagList of all files / subfolders in a given directory. This is shown in the following example:

String folder 
TagGroup FileList
number fFiles   = 1
number fFolders = 2

If ( !GetDirectoryDialog( "Select base folder", "", folder ) ) 
    Exit(0)

FileList = GetFilesInDirectory( folder, fFiles + fFolders )

If ( FileList.TagGroupCountTags() > 0 ) 
    FileList.TagGroupOpenBrowserWindow( "Files & Folders", 0 )

This script will show you the resulting TagGroup in a browser window like the one below. Each list entry is itself a TagGroup which contains a single tag "Name". This tag contains the file or folder name. You can use the command to either give you only files, only subfolders, or both.

Once you have the TagGroup of all entries, you process is like any other TagGroup in DigitalMicrograph. For example, you can browse the list to read out the strings and simple print them to the results window like this:

number nTags = FileList.TagGroupCountTags()
for ( number I = 0; I < nTags; i++ )
{
    TagGroup entryTG
    FileList.TagGroupGetIndexedTagAsTagGroup( i, entryTG )
    if ( entryTG.TagGroupIsValid() )
    {
        string filestr
        if ( entryTG.TagGroupGetTagAsString( "Name", filestr ) )
        {
            Result( "\n File:" + filestr )
        }
    }
}

这篇关于在DigitalMicrograph脚本中从文件夹打开多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆