public AddItem ( String fileOrDirectoryName, String directoryPathInArchive ) : |
||
fileOrDirectoryName | String | the name of the file or directory to add. /// |
directoryPathInArchive | String |
/// The name of the directory path to use within the zip archive. This path
/// need not refer to an extant directory in the current filesystem. If the
/// files within the zip are later extracted, this is the path used for the
/// extracted file. Passing |
Résultat |
public ZipEntry AddItem(String fileOrDirectoryName, String directoryPathInArchive)
{
if (File.Exists(fileOrDirectoryName))
return AddFile(fileOrDirectoryName, directoryPathInArchive);
if (Directory.Exists(fileOrDirectoryName))
return AddDirectory(fileOrDirectoryName, directoryPathInArchive);
throw new FileNotFoundException(String.Format("That file or directory ({0}) does not exist!",
fileOrDirectoryName));
}
ZipFile::AddItem ( string fileOrDirectoryName ) : |
static string CreateFileToUpload(IList<string> files) { if (files == null || files.Count == 0) { Console.WriteLine("No files were supplied"); Environment.Exit(1); } string temporaryFile = Path.GetTempFileName() + ".zip"; using (var zip = new ZipFile()) { foreach (string file in files) { if (File.Exists(file) || Directory.Exists(file)) { zip.AddItem(file); } else if (file.Contains("*") || file.Contains("?")) { string parent = Path.GetDirectoryName(file); if (parent == null) { Console.WriteLine("Unabled to find file or folder: {0}", file); Environment.Exit(10); } string wildCard = Path.GetFileName(file); if (wildCard == null) { Console.WriteLine("Unabled to find file or folder: {0}", file); Environment.Exit(10); } foreach (FileInfo fileInPattern in new DirectoryInfo(parent).GetFiles(wildCard)) { zip.AddItem(fileInPattern.FullName); } } else { Console.WriteLine("Unabled to find file or folder: {0}", file); Environment.Exit(10); } } zip.Save(temporaryFile); } return temporaryFile; }