質問

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!

役に立ちましたか?

解決

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();
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top