void DirectorySize(System.IO.DirectoryInfo dinfo, ref DirectoryStats stats) { var i = 1; var dea = new DiskEventArgs { State = ScanState.Segment, Stats = stats }; try { foreach (System.IO.FileInfo fi in dinfo.GetFiles()) { stats.Size += fi.Length; stats.Files += 1; if (i++ % 100 == 0) { onTempScan?.Invoke(null, dea); } } foreach (System.IO.DirectoryInfo di in dinfo.GetDirectories()) { DirectorySize(di, ref stats); stats.Dirs += 1; if (i++ % 100 == 0) { onTempScan?.Invoke(null, dea); } } } catch { Log.Error("Failed to access temp folder: " + dinfo.FullName); } }
private void cbxAdvSearch_Click(object sender, RoutedEventArgs e) { //lblFileCount.Content = "Number of folders and files in Directory"; DirectoryStats directoryStats = StatsCreator.CreateDirectoryStats(dirInfo, cbxAdvSearch.IsChecked.Value); CalculateSize(directoryStats.DirectorySize); lblNumberOfFiles.Content = directoryStats.NumberOfFiles; }
private void btnChooseDir_Click(object sender, RoutedEventArgs e) { var dlg = new CommonOpenFileDialog() { Title = "Vælg en mappe", IsFolderPicker = true, AddToMostRecentlyUsedList = false, AllowNonFileSystemItems = false, EnsureFileExists = true, EnsurePathExists = true, EnsureReadOnly = false, EnsureValidNames = true, Multiselect = false, ShowPlacesList = true }; if (dlg.ShowDialog() == CommonFileDialogResult.Ok) { // TODO: // Show the path (found in dlg.FileName) in the correct textbox so the user can see what was chosen tbxDirPath.Text = dlg.FileName; cbxAdvSearch.IsEnabled = true; cbxModUTC.IsEnabled = false; dirInfo = new DirectoryInfo(dlg.FileName); // TODO: // Use the dirInfo to create a DirectoryStats object and show the relevant data for the user DirectoryStats directoryStats = StatsCreator.CreateDirectoryStats(dirInfo, cbxAdvSearch.IsChecked.Value); lblName.Content = directoryStats.Name; lblType.Content = "Directory"; CalculateSize(directoryStats.DirectorySize); //TODO: Needs to be fixed lblFileExtension.Content = "n/a"; imgIcon.Source = new BitmapImage(new Uri("Images/folder.png", UriKind.Relative)); wpFileCount.Visibility = Visibility.Visible; wpFileExtension.Visibility = Visibility.Collapsed; wpCreationTime.Visibility = Visibility.Collapsed; wpLastModified.Visibility = Visibility.Collapsed; cbxModUTC.IsChecked = false; } }
public async Task ScanTemp() { if (!Atomic.Lock(ref scantemp_lock)) { return; } try { await Task.Delay(0); var dst = new DirectoryStats { Files = 0, Dirs = 0, Size = 0 }; ReScanBurden = 0; Log.Information("Temp folders scanning initiated..."); onTempScan?.Invoke(null, new DiskEventArgs { State = ScanState.Start, Stats = dst }); DirectorySize(new System.IO.DirectoryInfo(systemTemp), ref dst); if (systemTemp != userTemp) { onTempScan?.Invoke(null, new DiskEventArgs { State = ScanState.Segment, Stats = dst }); DirectorySize(new System.IO.DirectoryInfo(userTemp), ref dst); } onTempScan?.Invoke(null, new DiskEventArgs { State = ScanState.End, Stats = dst }); Log.Information("Temp contents: {Files} files, {Dirs} dirs, {Size} MBs", dst.Files, dst.Dirs, string.Format("{0:N2}", dst.Size / 1000f / 1000f)); } catch { throw; } // for finally block finally { Atomic.Unlock(ref scantemp_lock); } }