Klipfolio Dashboard 5 API

Object File

Object
   |
   +--File

The File object provides an interface for querying various properties on a file.

Klip Security Model

Using the API calls below requires running with developer mode enabled and having the XML <scriptmode>extended</scriptmode> within the Klip's <setup> block, as shown below.

   <setup>
     <scriptmode>
       extended
     </scriptmode>
   </setup>
 
In developer mode, select "Allow Blocked Script to Run" from the Klip's Developer Tools menu.

In order to use this object without the Developer Mode turned on, you must have your Klip digitally signed by Klipfolio Inc.

Example: Accessing c:\temp\test.xml

The following Klip creates a File object using Engines.File.open() to access the local file c:\temp\test.xml.

Before running this Klip, save a copy of demo-static.html to c:\temp\test.xml on your computer.

<klip>
   <identity>
      <title>
         API: File
      </title>
   </identity>
   <locations>
      <icon>
         http://www.klipfolio.com/static/klips/klipfolio/sample_icon.png
      </icon>
      <banner>
         http://www.klipfolio.com/static/klips/klipfolio/sample_banner.png   
      </banner>
   </locations>
   <setup>
      <scriptmode>
         extended
      </scriptmode>
   </setup>
   <style>
      alert {
         type: item;
      }

      sender {
         itemcol: 2;
         noterow: 1;

         label: 'Sender';

         emphasis: strong;
      }


      summary {
         itemcol: 3;
         noterow: 4;

         wrap: false;

         notelabel: false;
      }

      date {
         itemcol: 4;
         noterow: 2;

         label: 'Date';
      }

      category {
         noterow: 3;

         label: 'Category';
      }


      level {
         itemcol: 1;
         noterow: 5;
         notelabel: false;
         
         type: image;
      }

      url {
         type: link;
      }
            
      id {
         key: override;
      }

   </style>
   <klipscript>
   <![CDATA[

      
     // Place the contents of 
     // 	
     // 	http://support.klipfolio.com/files/demo/demo.xml
     // at
     // 
     // 	c:\temp\test.xml
     // 
     // and reload this Klip.
      	
function onRefresh ()
{	
	var path = "c:\\temp\\test.xml";	// UNC path to file
	
	var F, data;	

	F = Engines.File.open (path);	
	if (!F.exists)				// Check if file exists
	{
		_t( "File not found: " + path );
		return false;
	}
	
	show_file_properties( F )
	if (data = F.read ()) 		// Read contents of file
	{
		return Engines.Data.process( data );
	} 

	//
	// Why no F.close()?
	//
	// Klipfolio Dashboard never keeps a file open.  The calls to File.open()
	// and File.read() both open and close the file within the function call.
	//
	// So on exit, the file has already been closed by the last File.read().
	//
}

function show_file_properties( F )
{
	_t( "             name: " + F.name );
	_t( "             path: " + F.path );
	_t( "           exists: " + F.exists );
	_t( "             size: " + F.size );
	_t( "     lastmodified: " + F.lastmodified );
	_t( "       lastaccess: " + F.lastaccess );
	_t( "         creation: " + F.creation );
	_t( "       attributes: " + F.attributes );
	_t( "         readonly: " + F.readonly );
	_t( "           system: " + F.system );
	_t( "          archive: " + F.archive );
	_t( "           device: " + F.device );
	_t( "           normal: " + F.normal );
	_t( "        temporary: " + F.temporary );
	_t( "       sparsefile: " + F.sparsefile );
	_t( "     reparsepoint: " + F.reparsepoint );
	_t( "       compressed: " + F.compressed );
	_t( "          offline: " + F.offline );
	_t( "notcontentindexed: " + F.notcontentindexed );
	_t( "        encrypted: " + F.encrypted );
}

function _t(s) 
{
	trace( s + "\r\n" );
}

]]>
	</klipscript>
</klip>

     	
When run in developer mode, the Klip outputs the following to the Debug Window.

Note: Because this Klip uses script that accesses your hard drive, you will see a warning in your Klip when you try to run it. Select "Allow Blocked Script to Run" from the Developer Tools option to run the Klip.

              name: test.xml
              path: c:\temp
            exists: true
              size: 721
      lastmodified: 1217534849
        lastaccess: 1217534849
          creation: 1214500288
        attributes: 32
          readonly: false
            system: false
           archive: true
            device: false
            normal: false
         temporary: false
        compressed: false
           offline: false
 notcontentindexed: false
         encrypted: false
 

After the Klip loads, try editing contents of test.xml and refreshing the Klip.


Properties Summary
 boolean archive
          Returns true if file's archive bit is set, otherwise false.
 integer attributes
          Returns the file's attributes as a bitmap.
 boolean compressed
          Returns true if the file is compressed, otherwise false.
 integer creation
          Returns creation timestamp.
 boolean device
          Returns true if the file is a device, otherwise false.
 boolean encryted
          Returns true if the file is encrypted, otherwise false.
 boolean exists
          Returns true if file exists, otherwise false.
 boolean hidden
          Returns true if file is hidden, otherwise false.
 integer lastaccess
          Returns lastaccess timestamp.
 integer lastmodified
          Returns lastmodified timestamp.
 String name
          The name of the file.
 boolean normal
          Returns true if the file is a normal, otherwise false.
 boolean notcontentindexed
          Returns true if the file is notcontentindexed, otherwise false.
 boolean offline
          Returns true if the file is offline, otherwise false.
 String path
          The path to the directory containing the file.
 boolean readonly
          Returns true if file is readonly, otherwise false.
 integer size
          Returns size of file (in bytes).
 boolean temporary
          Returns true if the file is a temporary, otherwise false.
   
Function Summary
 String read()
           Read data from a file.

Properties Detail

archive

boolean archive

attributes

integer attributes

compressed

boolean compressed

creation

integer creation

device

boolean device

encryted

boolean encryted

exists

boolean exists

hidden

boolean hidden

lastaccess

integer lastaccess

lastmodified

integer lastmodified

name

String name

normal

boolean normal

notcontentindexed

boolean notcontentindexed

offline

boolean offline

path

String path

readonly

boolean readonly

size

integer size

temporary

boolean temporary

Function Detail

read

String read()

Klipfolio Dashboard 5 API

© 2009 Klipfolio Inc. All Rights Reserved.