3

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!

Andrea Silvestri
  • 1,082
  • 4
  • 14
  • 41

1 Answers1

3

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();
}
Dom
  • 2,569
  • 1
  • 18
  • 28
  • this is very helpful though I have a problem with the .cmd file... if I copy and paste the as3 generated string in the prompt window everything it's ok, but if I run the hide.cmd file (both via air and doubleclick) nothing happens... =\ – Andrea Silvestri May 08 '12 at 21:02
  • 1
    Try adding "pause" at the end of your hide.cmd file and manually running it. The pause command will make the command prompt stay open allowing you to read if there are any errors. Not much of a DOS person but let me know if you see anything in there and I will try to assist more. – Dom May 08 '12 at 21:13
  • The returned error is this: `C:\Users\ANDREA\Desktop>´╗┐attrib +h "C:\Users\ANDREA\Desktop\.prova" "´╗┐attrib" is not recognized as an internal or external command, an executable program or batch file` Since I'm not at home I created this cmd file by making a new one with notepad. It seems the prompt reads strange symbols I didn't type °_° – Andrea Silvestri May 09 '12 at 13:38
  • what is the exact command that you are trying to have the .cmd file run? I know you said it works by copy paste into the cmd prompt so it SHOULD work in the batch file. Let me know the command you are trying to use (without the crazy special characters) and I will do some testing. – Dom May 09 '12 at 15:29
  • Im on a Mac right now so I will not be able to test. Will take a look tonight at home and get back to you. – Dom May 09 '12 at 17:54
  • ok, found the issue. .omgtoolcheck should be omgtoolcheck.txt. You have two issues. First, there is a "." in front of the file name when there shouldnt be one. Next, you dont have the file extension of the file you are trying to make hidden. If it is a .txt file, add .txt. If .exe, add .exe. Hope that helps. – Dom May 09 '12 at 22:43
  • description in italian but... same error =( http://dl.dropbox.com/u/4064417/sameError.JPG – Andrea Silvestri May 10 '12 at 10:08
  • That's weird. The cmd file worked fine on my machine. The command I used was the exact same except I replaced your username with my username and dont have the crazy special characters in there. ACTUALLY!!!! I have seen this before. When writing a file with ActionScript I have seen it put crazy text in the front of the file. I have no idea how I fixed it though. I will post again if I can remember. – Dom May 10 '12 at 11:53
  • This comments section is getting pretty long... For some reason I cant move it to chat... Anyways, I am going to update my answer to give code of the way I THINK it should work. Let me know if its how you are doing things. – Dom May 11 '12 at 09:52
  • 1
    GOT IT! the line which writes the stream should be like this: `stream.writeMultiByte( dataString, "ANSI" );` You should update your answer =) – Andrea Silvestri May 13 '12 at 17:44
  • Great!!! Glad you figured it out. Updated that line in the answer. Good luck out there! – Dom May 13 '12 at 21:35