March 26, 200916 yr 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.
April 14, 200916 yr 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; } }
May 9, 200916 yr Author 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).
May 15, 200916 yr 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/
May 18, 200916 yr Author 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...
Create an account or sign in to comment