Opening multiple files from folder in DigitalMicrograph scripting

前端 未结 1 2036
攒了一身酷
攒了一身酷 2021-01-23 21:39

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 OpenImag

相关标签:
1条回答
  • 2021-01-23 22:27

    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.

    enter image description here

    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 )
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题