public void RenderFilesWithDeep(string path, string side) { Stack <string> dirs = new Stack <string>(20); FolderCmpItem cpmItem = new FolderCmpItem(); if (!Directory.Exists(path)) { throw new ArgumentException(); } dirs.Push(path); while (dirs.Count > 0) { string currentDir = dirs.Pop(); string[] subDir = Directory.GetDirectories(currentDir); string filter = filterExtension.Text; FileInfo[] files = MyFile.GetFiles(currentDir, filter); addDirectoryNameItem(currentDir, side); foreach (FileInfo file in files) { addFileNameItem(file, path, side); } foreach (string str in subDir) { dirs.Push(str); } } }
private void CompareFilesInFolder(string leftPath, string rightPath) { string filter = filterExtension.Text; filesToRightPathCopy.Clear(); filesToLeftPathCopy.Clear(); leftFiles = MyFile.GetFiles(leftPath, filter); rightFiles = MyFile.GetFiles(rightPath, filter); string imgPath; FolderCmpItem cpmItem = new FolderCmpItem(); string pathToCopy; if (leftFiles.Length > 0 || rightFiles.Length > 0) { SyncBtn.IsEnabled = true; } foreach (FileInfo file in leftFiles) { int index = Array.IndexOf(rightFiles, rightFiles.FirstOrDefault(f => f.Name == file.Name)); if (index > -1) { FileInfo secondFile = rightFiles[index]; imgPath = EQUAL_IMG; string redItem = "red"; if (byDate.IsChecked == true) { string dateFile_1 = MyFile.GetFileDate(file); string dateFile_2 = MyFile.GetFileDate(secondFile); DateTime nowdate = DateTime.Today; DateTime filedate_1 = file.LastWriteTime; DateTime filedate_2 = secondFile.LastWriteTime; TimeSpan comparevalue = filedate_2 - filedate_1; if (Math.Abs(comparevalue.Seconds) > 0) { imgPath = NOT_EQUAL_IMG; pathToCopy = BuiltPathToCopy(file, LEFT); ListCmpFilesCollections.Add(cpmItem.createCmpItem(file, secondFile, imgPath, NOT_EQUAL_COPY_BY_DATE, rightPath, pathToCopy, redItem)); } else { pathToCopy = BuiltPathToCopy(file, RIGHT); ListCmpFilesCollections.Add(cpmItem.createCmpItem(file, secondFile, imgPath, NOT_EQUAL_COPY_BY_DATE, leftPath)); } } else { ListCmpFilesCollections.Add(cpmItem.createCmpItem(file, secondFile, imgPath, EQUALLY, leftPath)); } //delete this file in rightFiles List <FileInfo> tmp = new List <FileInfo>(rightFiles); tmp.RemoveAt(index); rightFiles = tmp.ToArray(); } else { imgPath = LEFT_ARROW_IMG; pathToCopy = BuiltPathToCopy(file, LEFT); ListCmpFilesCollections.Add(cpmItem.createCmpItem(file, null, imgPath, NOT_EXIST_RIGHT_SIDE, leftPath, pathToCopy)); filesToRightPathCopy.Add(file); } } foreach (FileInfo secondFile in rightFiles) { imgPath = RIGHT_ARROW_IMG; pathToCopy = BuiltPathToCopy(secondFile, RIGHT); ListCmpFilesCollections.Add(cpmItem.createCmpItem(null, secondFile, imgPath, NOT_EXIST_LEFT_SIDE, rightPath, pathToCopy)); filesToLeftPathCopy.Add(secondFile); } foldersCmpList.ItemsSource = ListCmpFilesCollections; }
private void BuildList(string path, ListView listFiles) { listFiles.ItemsSource = null; listFiles.Items.Clear(); var list = new System.Collections.Generic.List <MyViewItem>(); foreach (DirectoryInfo dir in MyFile.GetFolders(path)) { if ((dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { continue; } listFiles.View = MyGridView.CreateGridView(); list.Add(new MyViewItem { MyIcon = getIcon(dir.FullName), Name = dir.Name, Type = "<DIR>", Size = " ", Date = dir.LastAccessTime.ToShortDateString() + " " + dir.LastAccessTime.ToShortTimeString() }); } foreach (FileInfo file in MyFile.GetFiles(path)) { if ((file.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { continue; } listFiles.View = MyGridView.CreateGridView(); list.Add(new MyViewItem { MyIcon = getIcon(file.FullName), Name = file.Name, Type = file.Extension.Replace(".", ""), Size = Math.Round((file.Length / 1024f)).ToString() + " Kb", Date = file.LastAccessTime.ToShortDateString() + " " + file.LastAccessTime.ToShortTimeString() }); } string pathTmp; if (listFiles.Name == "leftListFiles") { pathTmp = leftPath; } else { pathTmp = rightPath; } DirectoryInfo DirInfo = new DirectoryInfo(pathTmp); MyViewItem noRootItem = new MyViewItem { MyIcon = null, Name = ". . .", Type = "", Size = "", Date = "" }; if (DirInfo.Root.ToString() != DirInfo.FullName.ToString()) { listFiles.View = MyGridView.CreateGridView(); list.Insert(0, noRootItem); } listFiles.ItemsSource = list; listFiles.SelectedIndex = 0; }