Example #1
0
        /// <summary>
        /// Perform a rename in a directory using the specified patterns and options
        /// </summary>
        /// <param name="origNames"></param>
        /// <param name="newNames"></param>
        /// <param name="optionSubDirs"></param>
        /// <param name="optionListOnly"></param>
        /// <param name="optionVerbose"></param>
        /// <returns></returns>
        static private int Rename(string origNames, string newNames, bool optionSubDirs, bool optionListOnly, bool optionVerbose)
        {
            if (optionVerbose)
            {
                if (optionListOnly)
                {
                    Console.WriteLine("Preview of renaming " + origNames + " to " + newNames + ":");
                }
                else
                {
                    Console.WriteLine("Renaming " + origNames + " to " + newNames + ":");
                }
            }

            string currentDir = CurrentDir();

            // Create a FileNameRegex for the whole file name
            FileNameRegex r = new FileNameRegex("^" + origNames + "$");

            RegExDirInfo dirInfo = new RegExDirInfo(currentDir, optionSubDirs, r);

            dirInfo.Rename(currentDir, newNames, optionListOnly);

            return(0);
        }
Example #2
0
        /// <summary>
        /// Perform a listing of a directory using the specified filter and options
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="optionSubDirs"></param>
        /// <param name="optionVerbose"></param>
        /// <returns></returns>
        static private int DirList(string filter, bool optionSubDirs, bool optionVerbose)
        {
            // Create a FileNameRegex for the whole file name
            FileNameRegex r = new FileNameRegex("^" + filter + "$");

            if (optionVerbose)
            {
                Console.WriteLine("Listing of " + filter + ":");
            }

            string currentDir = CurrentDir();

            RegExDirInfo dirInfo = new RegExDirInfo(currentDir, optionSubDirs, r);

            dirInfo.List(currentDir, optionVerbose);

            return(0);
        }
Example #3
0
        /// <summary>
        /// Constructor. Create a new object and fill files and directories
        /// </summary>
        /// <param name="baseDir">The base dir, ending in backslash</param>
        /// <param name="subDirs">If true, also search subdirectories of base directory</param>
        /// <param name="r">The file name regex to use</param>
        public RegExDirInfo(string baseDir, bool subDirs, FileNameRegex r)
        {
            this.baseDir = baseDir;
//      this.filter = filter;
            this.regex = r;

            // Get files in directory, then match
            DirectoryInfo dirInfo = new DirectoryInfo(baseDir);

            FileInfo[] files = dirInfo.GetFiles();

            this.files = new ArrayList();

            for (int i = 0; i < files.Length; i++)
            {
                if (r.IsMatch(files[i].Name))
                {
                    this.files.Add(files[i].Name);
                }
            }

            // Set up a list of subdirectories
            this.directories = new ArrayList();

            // Get subdirectories and match those, if necessary
            if (subDirs)
            {
                DirectoryInfo[] directories = dirInfo.GetDirectories();
                foreach (DirectoryInfo directory in directories)
                {
                    RegExDirInfo subDir = new RegExDirInfo(directory.FullName + "\\", subDirs, r);
                    if (subDir.files.Count != 0)
                    {
                        this.directories.Add(subDir);
                    }
                }
            }
        }