Creating Hidden File with Flex/AIR on Win

痴心易碎 提交于 2019-12-07 15:28:52

问题


how can I create a hidden file on my Win filesystem? I've read you should use native code and I know AS3 has got NaviteProcess class but I really don't know how to use it and I don't manage to find much about it.

Is there anyone who knows how to do it?

Thank you in advance!


回答1:


Cleaned up to better reflect where we are and will keep it updated:

Based on info from: http://deepanjandas.wordpress.com/2010/09/10/writing-executing-cmd-scripts-through-air/

private var applicationDirectory:File;

private function createCMDFile():void
{
    applicationDirectory = File.desktopDirectory;
    var cmdFile:File = applicationDirectory.resolvePath( 'hide.cmd' );
    var stream:FileStream = new FileStream()
    stream.open( cmdFile, FileMode.WRITE );

    var dataString:String = "ATTRIB +H \\ C:\\Users\\***yourUserName***\\***fileToHide.txt***"; //or any path you want just be sure to use \\ instead of \ and obviously change ***yourUserName*** and ***fileToHide.txt***

            stream.writeMultiByte( dataString, "ANSI" );
    stream.close();

    stream = null;

    var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
    nativeProcessStartupInfo.executable = cmdFile;

    var process:NativeProcess = new NativeProcess();
    process.start(nativeProcessStartupInfo);
    process.addEventListener( NativeProcessExitEvent.EXIT, onExitHandler );
}

private function onExitHandler( event:NativeProcessExitEvent ):void
{
    var cmdFile:File = applicationDirectory.resolvePath( 'hide.cmd' );
    cmdFile.deleteFile();
}


来源:https://stackoverflow.com/questions/10489952/creating-hidden-file-with-flex-air-on-win

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!