Opening multiple files from folder in DigitalMicrograph scripting

大兔子大兔子 提交于 2019-12-02 06:44:09

问题


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?


回答1:


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 )
        }
    }
}


来源:https://stackoverflow.com/questions/26713158/opening-multiple-files-from-folder-in-digitalmicrograph-scripting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!