public static MyDirInfo GetArchiveDirectoryInfo(MyDirInfo mdi, string archiveFileName, string tempFolder) { string extractToDir = tempFolder + "\\" + GetTimeStamp(); if (!ExtractArchive(archiveFileName, extractToDir)) { return(null); } if (mdi == null) { mdi = new MyDirInfo(); mdi.ParentDir = null; DirectoryInfo di = new DirectoryInfo(extractToDir); mdi.name = "/"; mdi.modified = di.LastWriteTime; mdi.created = di.CreationTime; mdi.size = 0; mdi.type = 2; mdi.extractedFile = extractToDir; } mdi.Children = GetDirectoryInfoRecursiveExpandArchives(mdi, extractToDir, tempFolder); //Delete created dir if (DelFiles) { if (Directory.Exists(extractToDir)) { Directory.Delete(extractToDir, true); } } return(mdi); }
public static List <MyDirInfo> GetDirectoryInfoRecursiveExpandArchives(MyDirInfo mdi, string Folder, string tempFolder) { List <MyDirInfo> mdiList = new List <MyDirInfo>(); if (!Directory.Exists(Folder)) { return(mdiList); } /* * mdi.ParentDir=null; * DirectoryInfo di=new DirectoryInfo(Folder); * mdi.name=di.Name; * mdi.modified=di.LastWriteTime; * mdi.created=di.CreationTime; * mdi.type=1; * mdi.size=0; */ string [] Files = Directory.GetFiles(Folder); //Add all child first foreach (string file in Files) { if (IsArchive(file)) { MyDirInfo mdiChildArchive = new MyDirInfo(); mdiChildArchive.ParentDir = mdi; DirectoryInfo di = new DirectoryInfo(file); mdi.name = "/"; mdi.modified = di.LastWriteTime; mdi.created = di.CreationTime; mdi.size = 0; mdi.type = 2; //mdi.extractedFile=extractToDir; //mdi.Children=GetArchiveDirectoryInfo(null,file,tempFolder); mdiList.Add(mdiChildArchive); } else { MyDirInfo mdiChild = new MyDirInfo(); FileInfo fi = new FileInfo(file); mdiChild.ParentDir = mdi; mdiChild.name = fi.Name; mdiChild.created = fi.CreationTime; mdiChild.modified = fi.LastWriteTime; mdiChild.Children = null; mdiChild.size = fi.Length; mdiChild.type = 0; mdiChild.extractedFile = file; mdiList.Add(mdiChild); if (SaveContents) { mdiChild.Contents = File.ReadAllBytes(file); } } } string [] dirs = Directory.GetDirectories(Folder); //Get all directories now foreach (string dir in dirs) { MyDirInfo mdiSubFolder = new MyDirInfo(); DirectoryInfo di = new DirectoryInfo(dir); mdiSubFolder.name = di.Name; mdiSubFolder.created = di.CreationTime; mdiSubFolder.modified = di.LastWriteTime; mdiSubFolder.Children = GetDirectoryInfoRecursiveExpandArchives(mdiSubFolder, dir, tempFolder); mdiSubFolder.ParentDir = mdi; mdiSubFolder.extractedFile = dir; mdiList.Add(mdiSubFolder); } return(mdiList); }