A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: AIR - extract files to folder

  1. #1
    Senior Member
    Join Date
    Nov 2000
    Location
    Denmark
    Posts
    159

    AIR - extract files to folder

    Hi Guys,

    I working on my first Air app.

    What I want to do is to extract a zip file to a specific folder.

    I am using the code below that promts the user to choose which directory the zip should be extracted to and the extracts it succesfully.

    Now I would like define a fixed folder where the files should be axtracted to instead of letting the user decide.

    Anyone who know how to do that ?

    Thanx in advance.



    (Using zip libary from: http://nochump.com/blog/archives/15 )

    Actionscript Code:
    function extractZIP():void {
       
        output.text = "extractZIP MANUAL";     
        zipOutput.browseForDirectory("Select Directory for extract");
        zipOutput.addEventListener(Event.SELECT, onDirSelect);
    }

    function onDirSelect(e:Event=null):void {
       
        for (var i:uint = 0; i < zipFile.entries.length; i++) {
           
            var zipEntry:ZipEntry=zipFile.entries[i] as ZipEntry;
            // The class considers the folder itself (without the contents) as a ZipEntry.  
            // So the code creates the subdirectories as expected.  
           
            if (! zipEntry.isDirectory()) {
                var targetDir:File = e.target as File;         
                var entryFile:File = new File();
                entryFile = targetDir.resolvePath(zipEntry.name);
                var entry:FileStream = new FileStream();
                entry.open(entryFile, FileMode.WRITE);
                entry.writeBytes(zipFile.getInput(zipEntry));
                entry.close();
            }
           
        }
       
    }

  2. #2
    Senior Member
    Join Date
    Apr 2008
    Location
    Rotorua / New Zealand
    Posts
    117
    Looking at this code it seems that you are on the right way, but I have to assume things as there is not enough code e.g. imports etc to look at it properly.
    You seem to have still directory stuff in there ??? which should be changed against code needed for the operation in AIR !
    The one thing which is missing is to have a pathway for sure as you have already the WRITE section so try to look at the the pathway similar to this !

    Code:
    var entryFile:File = File.desktopDirectory.resolvePath("directory/MyFile.zip");
    ....
    entry.openAsync(entryFile, FileMode.WRITE);
    ....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center