David Wikström Posted March 26, 2009 Posted March 26, 2009 Anyone got the recipe for extracting files from a zip-file (stored in a container field, though that's probably irrelevant since I can export it) to a specified location? I need it to work on Windows XP and Vista.
patate Posted April 14, 2009 Posted April 14, 2009 Maybe, it will help... On extracting files, it will not retain the subfolders tree. It will also create a temporary folder to extract the files. If you want other ideas: Java Examples int unZipPhoto(String filePath, String tempPath, String tempFolderName){ try{ //Créer folder temp new File(tempPath + tempFolderName).mkdir(); String pattern2="^.*/(.*..*)$"; Pattern patternObj = Pattern.compile(pattern2); Matcher matcherObj; ZipFile zf = new ZipFile(filePath); Enumeration e = zf.entries(); while (e.hasMoreElements()) { ZipEntry ze = (ZipEntry) e.nextElement(); if (ze.getName().substring(1,2) != "_"){//Ne pas prendre les ressources if (ze.getName().matches(pattern2)){ //Vérifier présence d'un sous-dossier matcherObj = patternObj.matcher(ze.getName()); matcherObj.find(); entryFilename = matcherObj.group(1); }else{ entryFilename=ze.getName(); } FileOutputStream fout = new FileOutputStream(tempPath + tempFolderName + "/" + entryFilename); InputStream in1 = zf.getInputStream(ze); for (int c = in1.read(); c != -1; c = in1.read()) { fout.write©; } in1.close(); fout.close(); } } return 1; }catch (Exception e){ return 0; } }
David Wikström Posted May 9, 2009 Author Posted May 9, 2009 On extracting files, it will not retain the subfolders tree. In my case, I absolutely need to preserve the full file and folder hierarchy. I've looked at various other solutions for unzipping files, and various failed for the same reason... I can do this very nicely with PHP, so it looks like I'm going to have to get the SmartPill plug-in for this; not a big deal, but it really feels like overkill for what I'm trying to achieve (and I need this to work without an internet connection).
patate Posted May 15, 2009 Posted May 15, 2009 I'm pretty sure there is something to do to preserve the hierarchy in my script. Also, have you looked the dacon's FileFire plugin? http://www.dacons.net/fmplugins/filefireadvanced/
David Wikström Posted May 18, 2009 Author Posted May 18, 2009 I'm certain it can be done in Java - I just don't have the time to do enough trial-and-error to get this working (my knowledge of java is very limited). The Dacons plug-in does however look very promising - I actually hadn't heard of it. The Medium developer license isn't that expensive, considering the time I'd spend to get something else working. Will have to test it a bit more - my first attempt on a Mac worked fine except that I get an unwanted "_MACOSX" folder...
Recommended Posts
This topic is 5679 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now