OWASP O2 Platform Blog

O2 Script: Quick File Viewer

This is the script that I usually write ‘live’ in the training sessions I do about O2.

It is a simple file viewer which gets a list of all files in a folder and shows them in a text box (a variation is to use a sourceCodeViewer instead)

var topPanel = O2Gui.open<Panel>("{name}",800,400);
//var topPanel = panel.clear().add_Panel();
var textViewer = topPanel.add_RichTextBox();  //add_SourceCodeEditor();
var treeView = textViewer.insert_Left<Panel>(200).add_TreeView();
var sourceFolder = treeView.insert_Above<Panel>(20).add_TextBox("Folder:   ","");
var fileFilter = treeView.insert_Above<Panel>(20).add_TextBox("File Filter:","*.cs");

Action<string> loadFiles =
    (folder) =>    {
                    foreach(var file in folder.files(true, fileFilter.get_Text()))
                        treeView.add_Node(file.remove(folder), file);

Action loadFromSourceFolder =

sourceFolder.onEnter((text)=> loadFiles(text));
fileFilter.onEnter((text)=> loadFromSourceFolder());
sourceFolder.onDrop((folder)=> loadFiles(folder));
treeView.onDrop((folder)=> loadFiles(folder));
textViewer.onDrop((folder)=> loadFiles(folder));
textViewer.set_Text("Drag and Drop folder to open (and list files) into this GUI");
return "done";               

March 26, 2011 - Posted by | Windows Tools

1 Comment »

  1. […] O2 Script: Quick File Viewer […]

    Pingback by Script to fetch and present large number of Wordpress.com blog entries « O2Platform.com for Developers | April 16, 2011 | Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: