在新创建的目录中保存“ Tiff”堆栈时引发IOException

时间:2019-04-26 14:53:21

标签: imagej imagej-macro

我在编写宏时遇到问题,该宏以单个堆栈(分批)的方式打开.tif文件的大文件夹,然后将处理后的堆栈保存在新的目标文件夹中,同时保留了一些有关原始目录的信息。这很重要,因为原始目录按日期排序,并且包含有关每个子文件夹中文件的一些信息。

到目前为止,我已经读到,当字符串变量不在括号中时会出现问题,但是我无法在输出目录中包含的任何变量中添加括号,因为这会导致错误(预期数字或数字运算符)。如果我在日志文件中打印了所有变量,则它们都将正确读取。但是,每次都会抛出IOException,并且始终显示输出路径的截断版本。截断可能发生在单词和数字的中间。


#@ File (label = "Input directory", style = "directory") input
#@ File (label = "Output directory", style = "directory") output
#@ String (label = "File suffix", value = ".tif") suffix

// See also Process_Folder.py for a version of this code
// in the Python scripting language.

processFolder(input);

// function to scan folders/subfolders/files to find files with correct suffix
function processFolder(input) {
    list = getFileList(input);
    list = Array.sort(list);
    for (i = 0; i < list.length; i++) {
        if(File.isDirectory(input + File.separator + list[i]))
            processFolder(input + File.separator + list[i]);
        if(endsWith(list[i], suffix))
            processFile(input, output, list[i]);
    }
}

function processFile(input, output, file) {
    setBatchMode(true); 
    // prevents image windows from opening while the script is running
    run("Bio-Formats Importer", "open=[" + input + "/" + file +"] autoscale color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT"); 
    // open image using Bio-Formats

    cutoffFolder = "Raw Data";
    //change "Raw Data" to be any folder you want (as long as it is listed in the image path). This will be the highest order folder in the new directory


    oldDir = getDirectory("image");
    baseDir=indexOf(oldDir, cutoffFolder);
    subDir = substring(oldDir, baseDir, lengthOf(oldDir));
    subDir = substring(subDir, indexOf(subDir, cutoffFolder) + lengthOf(cutoffFolder), lengthOf(subDir));
    newDir = output +  "\\Analyzed\\" + subDir;
    newDir = replace(newDir, "\\ ", "\\_");
    //above code creates a new directory in your target 'output' folder that will mimic the original directory, preserving organization. 


    //  print("Output= ", output);
    //  print("Original directory= ", oldDir);
    //  print("Cutoff index= ", baseDir);
    print("subDir= ", subDir);
    print("newDir= ", newDir); 


    File.makeDirectory(newDir);     
    filename = File.nameWithoutExtension();
    //print(filename);

    saveAs("Tiff", newDir + filename + ".tif"); 

}

我本质上希望此宏打开一个'.env'文件(元数据),打开一个超级堆栈(工作),然后将超级堆栈保存到输出目录指定的新位置,并带有原始路径定义的其他子文件夹。例如, C:\ Users \ turnerbd_DR \ Raw_Data \ DateX \ ExperimentX \ File.env 将保存在桌面上的目标目录中(已处理) C:\ Users \ turnerbd_DR \ Desktop \ Processed \ Analyzed \ DateX \ ExperimentX File.tif

0 个答案:

没有答案