Ejemplo n.º 1
0
        private void FileUnZipOrRar(IEnumerable <string> fileNames)
        {
            var treeModelTemp = new ObservableCollection <TreeModel>();

            foreach (var item in fileNames)
            {
                DirectoryInfo root  = new DirectoryInfo(item);
                FileInfo[]    files = root.GetFiles();

                foreach (var file in files)
                {
                    // 新建一个文件夹
                    var folderStr = FileHelper.CrateFolder(file.FullName);
                    _newFolderStr = folderStr;

                    // 解压文件
                    RarClass.UnRar(file.FullName, folderStr);

                    // 删除原来的文件
                    File.Delete(file.FullName);

                    bool isHasParentDirectoryName = false;

                    // 获取:获取解压后的文件名称
                    var folder = StringOperation.FilePthAndName(file.FullName, out isHasParentDirectoryName);

                    // 创建一级树
                    CreateOneLevelTree(folderStr, file.Name);
                    // 创建文件树
                    FileHelper.GetDirectory(FileTree.Nodes, folder);
                    // 创建树集合
                    treeModelTemp.Add(FileTree);
                }
            }

            if (treeModelTemp.Count > 0)
            {
                FileTreeList    = new ObservableCollection <TreeModel>(treeModelTemp);
                PanelVisibility = Visibility.Visible;
            }
            else
            {
                MessageBox.Show("没有压缩文件!");
            }
        }