Exemplo n.º 1
0
        private void CountFolder(string folder)
        {
            folder = ShellFileRoutines.ShortPathName(folder);

            int total = 0;
            if (false == Directory.Exists(folder))
                return;

            DirectoryInfo di = new DirectoryInfo(folder);
            foreach (string filter in FILTERS)
            {
                m_counting.WaitOne();
                if (m_cancelCount)
                    break;

                try
                {
                    FileInfo[] fileInfoCollection = di.GetFiles(filter, SearchOption.TopDirectoryOnly);
                    total += fileInfoCollection.Length;
                    m_found += fileInfoCollection.Length;
                    foreach (FileInfo fileInfo in fileInfoCollection)
                    {
                        lock (m_files)
                        {
                            m_files.Enqueue(fileInfo.FullName);
                        }

                        m_counting.WaitOne();
                        if (m_cancelCount)
                            break;
                    }
                }
                catch (UnauthorizedAccessException e)
                {
                    System.Diagnostics.Trace.TraceError("Cannot access file/folder - " + e.Message);
                }
                catch (System.IO.PathTooLongException ptx)
                {
                    System.Diagnostics.Trace.WriteLine("Path too long: " + ptx.Message, "AuditInfo");
                }
                catch (System.Exception ptx)
                {
                    System.Diagnostics.Trace.WriteLine("Unknown file queueing exception : " + ptx.Message, "AuditInfo");
                }
            }
            if (OnFolderCount != null)
            {
                FolderCountEventArgs fca = new FolderCountEventArgs(folder, total);
                OnFolderCount(this, fca);
            }
            if (IncludeSubFolders)
            {
                try
                {
                    string parentDirectory = ShellFileRoutines.ShortPathName(di.FullName + "\\");
                    DirectoryInfo[] directoryCollection = di.GetDirectories();
                    foreach (DirectoryInfo directory in directoryCollection)
                    {
                        m_counting.WaitOne();
                        if (m_cancelCount)
                            break;

                        string shortPath = ShellFileRoutines.ShortPathName(parentDirectory + directory.Name);
                        CountFolder(shortPath);
                        Thread.Sleep(5);
                    }
                }
                catch (UnauthorizedAccessException e)
                {
                    System.Diagnostics.Trace.TraceError("Cannot access file/folder - " + e.Message);
                }
            }
        }
Exemplo n.º 2
0
 void m_fileSystemScanner_OnFolderCountProgress(object sender, FolderCountEventArgs e)
 {
     m_totalFiles += e.Total;
     if ( m_state == AuditState.Started )
         m_traceClient.NotifyItemCount(m_totalFiles);
 }