This is an archived page. It's not actively maintained.


This interface displays a list of files in a treebox.
Inherits from: nsISupports Last changed in Gecko 1.7

Note: nsIFileView is Linux-only interface. It's not included in Windows or Mac builds.

Note: A quirk of the nsIFileView is that it requires an appropriate treecols section in the tree tag, by default fileview will return the file size in the column. If the treecol id is "FilenameColumn" fileview will return the file name, if the id is "LastModifiedColumn" it will return the date of last modification. Currently no other file stats are implemented.

The nsIFileView provides a configuration interface to;1 , which also implements nsITreeView so that it can be passed as a tree view.

Implemented by:;1. To create an instance, use:

var fileView = Components.classes[";1"]

Method overview

void setDirectory(in nsIFile directory);
void setFilter(in AString filterString);
void sort(in short sortType, in boolean reverseSort);


Attribute Type Description
reverseSort boolean If true results will be sorted in ascending order. Read only.
selectedFiles nsIArray An nsIArray of selected files, which contains nsIArray instances. Read only.
showHiddenFiles boolean If true hidden files will be shown.
showOnlyDirectories boolean If true only directory entries will be returned.
sortType short The current sort type in effect. Read only.


Constant Value Description
sortName 0 Sort by file name.
sortSize 1 Sort by file size.
sortDate 2 Sort by the date of the last modification.



Set the directory to be browsed.

void setDirectory(
  in nsIFile directory
The directory to be browsed.


Set the filter to be applied to the file list, for example "*.jpg" would only return jpg files.

void setFilter(
  in AString filterString
The filter to be applied to the file list.


Set the method used for sorting.

void sort(
  in short sortType,
  in boolean reverseSort
One of the sort* constants.
true, results will be sorted in ascending order.


<?xml version="1.0" ?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css" ?>

<window id="test" title="Test" width="640" height="480"

	<tree flex="1" id="ftree">
                        <-- The default Column type is size unless an appropriate id is passed,
                            nsIFileView relies on the treecols section -->
			<treecol id="FilenameColumn" label="Name" flex="1" primary="true"/>
			<treecol id="LastModifiedColumn" label="Date" flex="1"/>
			<treecol id="Size" label="Size" flex="1"/>
		var DIR="/home/";    //The directory to be opened
		var ftree = document.getElementById("ftree");    //The XUL tree element

		var lfile = Components.classes[";1"]

		lfile.initWithPath(DIR);    // Open the directory

		var fview = Components.classes[";1"]
			.createInstance(Components.interfaces.nsIFileView);    //Create an instance of the component
		tview = fview.QueryInterface(Components.interfaces.nsITreeView);    //Get the nsITreeView interface

		fview.setDirectory(lfile.QueryInterface(Components.interfaces.nsIFile));    //Set the directory

		fview.setFilter("*");   //Add an appropriate file filter
		fview.sort(fview.sortName, false);    //Set the sort type

		ftree.view = tview;    //Set the view on the tree object