File list sample script

 

/* createFileList.qs

 

Creates a text file where all files of a certain type (BrainVoyager stimulation protocol files (*.prt) in this case) are listed, one filename on each line.

     On the first line, the number of filenames is written.

This file list can be used for the protocol to design matrix converter plugin  (ProtocolToDesignMatrix_v2.dll).

*/

 

function Create_file_list() {

 

var fileTypeExtension = "*.prt";

var filename = FileDialog.getOpenFileName(fileTypeExtension, "Please select a file in the directory where you'd like to make a filelist of");

var tmpfile = new File(filename);

var filepath = new Dir(tmpfile.path);

var fileList = filepath.entryList(fileTypeExtension);

 

BrainVoyagerQX.ShowLogTab();

BrainVoyagerQX.PrintToLog("Creating file list of " + fileTypeExtension + " files...");

var fileListFile = new File(filepath.path + "/filelist.txt");

fileListFile.open( fileListFile.WriteOnly );

var filenr;

fileListFile.writeLine(fileList.length.toString());

for (filenr = 0; filenr < fileList.length; filenr++) {

fileListFile.writeLine(fileList[filenr].toString());

}

fileListFile.close();

if (fileListFile.exists) {

BrainVoyagerQX.PrintToLog("Created filelist in " + fileListFile.fullName +"\nScript finished.");

} else {

BrainVoyagerQX.PrintToLog("Could not create filelist.\nExit");

}

}