Friday, August 5, 2011

Know File System using Flex/AIR in a Win Machnie

Below is a small code snippet to know File System info in a Windows Machine using Flex/AIR.

var ta1:TextArea = new TextArea();

protected function getFS(event:MouseEvent):void
{
try
{
ta1.text = '';
var processInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();

var commands:Vector. = new Vector.();
commands[0] = "fsinfo";
commands[1] = "statistics";
commands[2] = "c:";

processInfo.arguments = commands;
processInfo.executable = new File('C:/WINDOWS/system32/fsutil.exe');

process = new NativeProcess();

process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutPutProgress, false, 0, true);

process.addEventListener(NativeProcessExitEvent.EXIT, handleExit2);
process.start(processInfo);
}
catch(e:Error)
{
Alert.show(e.message,"Error");
}
}

protected function handleExit2(event:NativeProcessExitEvent):void
{
if(event.exitCode == 0)
{
var str:String = ta1.text;
str = str.split('\n')[0];
str = StringUtils.removeExtraWhitespace(str);
str = str.substr(str.lastIndexOf(' '), str.length);
Alert.show('File System of C drive: ' + str);
}
else
{
Alert.show('Unable to get File System details');
}
}


protected function onOutPutProgress(event:ProgressEvent):void
{
ta1.text += process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable);
}


fsutil (C:/WINDOWS/system32/fsutil.exe) is a utitlity/exe which gives a lot of info on file system in a windows machine. I used this only to extract some file system info but you can know more about 'fsutil' from here and explore more options yourself.

This code snippet uses some Flex AIR API's like NativeProcessStartupInfo and this code can be tested only after generating an executable (exe).

1 comment:

  1. You’re doing great work. In this blog we can get useful information. Thanks for posting this blog.....................................Please contact us to know more about Oracle Fusion Financials Training at Erptree

    ReplyDelete