私は、スキップする必要があり、ターゲットのZIP
ファイルに追加されないいくつかのフォルダを持つディレクトリを持っています。 Windows
に隠されたように私はそれらをマークし、次のように私は、Javaコードを使用してこの属性を照会することができますZip4j Zipからフォルダを除外する
new File("C:\\myHiddenFolder").isHidden();
しかし、私はそれらのそれぞれのディレクトリを追加スキップするには、以下のZip4j
ベースの方法でこれを使用する方法がわかりません:
public File createZipArchive(String sourceFilePath) throws ZipException, IOException
{
ZipParameters zipParameters = new ZipParameters();
zipParameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
zipParameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_ULTRA);
zipParameters.setEncryptFiles(true);
zipParameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
zipParameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
zipParameters.setPassword("MyPassword");
String baseFileName = FileNameUtilities.getBaseFileName(sourceFilePath);
String destinationZipFilePath = baseFileName + "." + EXTENSION;
ZipFile zipFile = new ZipFile(destinationZipFilePath);
File sourceFile = new File(sourceFilePath);
// Recursively add directories
if (sourceFile.isDirectory())
{
File[] childrenFiles = sourceFile.listFiles();
if (childrenFiles != null)
{
for (File folder : childrenFiles)
{
if (folder.isHidden()) // Nope, no recursive checking!
{
// This is the problem, it adds the parent folder and all child folders without allowing me to check whether to exclude any of them...
zipFile.addFolder(folder.getAbsolutePath(), zipParameters);
}
}
}
} else
{
// Add just the file
zipFile.addFile(new File(sourceFilePath), zipParameters);
}
return zipFile.getFile();
}
この方法は、(隠された)フォルダが最も高いレベルにある場合にのみ機能しますが、どの深度でも機能するはずです。
最初の隠しフォルダが見つかったときに停止するので、間違っています。私も実装を読んで、それが何をしているのです。 – BullyWiiPlaza