コード例 #1
0
ファイル: OrganiserBase.cs プロジェクト: philspain/ordoFile
        /// <summary>
        /// Traverse root directory's subdirectories to ascertain directory tree structure,
        /// also gather available filetype data.
        /// </summary>
        /// <param name="directory"> Directory to be traversed.</param>
        /// <param name="availableFileTypes"> List to be populated with all filetypes in directories</param>
        /// <param name="directory"> Directory to be traversed.</param>
        public static void TraverseDirectories(DirectoryModel directory, ObservableCollection <string> availableFileTypes = null)
        {
            directory.Name = System.IO.Path.GetFileName(directory.Path);

            try
            {
                // List of subdirectories and filetypes in the current directory.
                string[] dirs = Directory.GetDirectories(directory.Path, "*", SearchOption.TopDirectoryOnly);

                if (availableFileTypes != null)
                {
                    string[] files = Directory.GetFiles(directory.Path);

                    OrganiserBase.PopulateFileTypes(files, availableFileTypes);
                }

                if (dirs.Count() > 0)
                {
                    foreach (string dir in dirs)
                    {
                        // Traverse each subdirectory contained in current directory then
                        // add to directories subdirectory list

                        DirectoryModel childDirectory = directory.CreateAndAddSubdirectory(dir);

                        OrganiserBase.TraverseDirectories(childDirectory, availableFileTypes);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
コード例 #2
0
        /// <summary>
        /// Callback for running organisation thread.
        /// </summary>
        void DoWork()
        {
            _canWork = true;

            //Run as long as user does not change _canWork value.
            while (_canWork)
            {
                //If the user has chosen to include sub-directories in
                //the organisation. retrieve all directories contained
                //in the root directory and pass to the MoveFiles instance.
                //Otherwise, just add the root directory to the directory list.
                if (base._organiseSubDirectories)
                {
                    OrganiserBase.TraverseDirectories(RootDirectory);
                }

                base.Organise();
                GUIDispatcherUpdates.ClearCollection(RootDirectory.Subdirectories);

                if (_canWork)
                {
                    _sleeping = true;
                    Thread.Sleep(60000);
                    _sleeping = false;
                }
                else
                {
                    base._organisationThread.Abort();
                }
            }


            base._isWorking = false;
        }