User Tools

Site Tools


Privacy Policy


Version 2.50 is out since Jan 1st 2022

Frequently Asked Questions


Note for contributors

If you wish to create a new page in the DroidScript wiki, please click on the most appropriate namespace above and follow the notes for contributors there.

Because of spam, it has been necessary to add a CAPTCHA to the registration form and the save option for editing pages. You will not need to prove you are human if you are logged in, so please register.

Please feel free to improve any existing page, as well as adding new pages to increase the sum of public knowledge about DroidScript.

Formatting Syntax


Listing files on an NXT

(Sample code by Dave Smart taken from the DroidScript Google Group)

Here is an example of how to list all files on your Lego NXT brick:

//Called when application is started.
function OnStart()
	//Create our screen layout.
	//Create NXT controller object.
	nxt = app.CreateNxt();   
//Create the screen layout.
function CreateLayout()
	//Create the layout (with repeating pattern background).
	lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
	lay.SetBackground( "/Sys/Img/Tile.png", "repeat" );
	//Create 'Connect' button.
	btn = app.CreateButton( "Connect", 0.3,0.1, "Lego" );
	btn.SetMargins( 0,0,0,0.1 );
	btn.SetOnTouch( btn_OnTouch );  
	lay.AddChild( btn );
	//Create 'List Files' button.
	btnCon = app.CreateButton( "List Files", 0.3, 0.1, "Lego" );    
	btnCon.SetOnTouch( btnCon_OnTouch );     
	lay.AddChild( btnCon ); 
	//Add layout to the app.
	app.AddLayout( lay );
//Called when user presses connect.
function btn_OnTouch()
	//Show list of NXT devices.
//Called when 'List Files' button is pressed.
function btnCon_OnTouch( e )
	alert( ListFiles( "*.*" ) );
//List files on the NXT using a search pattern.
//eg. "*.rso" finds all sound files.
function ListFiles( pattern )
    //Find first matching file on nxt.
    var list = "";
    var inf = nxt.FileFindFirst( pattern );
    if( inf!=null ) list = inf.GetName();    
    //Find remaining files.
    while( 1 ) {
	    inf = nxt.FileFindNext( inf.GetHandle() );
	    if( inf==null ) break;
	    list += "," + inf.GetName();	    
    return list;
sample_code/listing_nxt_files.txt · Last modified: 2015/03/11 03:09 (external edit)