Пример #1
0
        /// <summary>
        /// Rename all files in this directory and subdirectories
        /// </summary>
        /// <param name="newNames">The replacement Regex pattern to rename to</param>
        /// <param name="previewOnly">If true, do not rename, only preview</param>
        public void Rename(string skipPrefix, string newNames, bool previewOnly)
        {
            // Set up a prefix for printing
            string prefix = baseDir;

            if (prefix.ToLower().StartsWith(skipPrefix.ToLower()))
            {
                prefix = prefix.Substring(skipPrefix.Length);
            }

            // Handle each file
            foreach (string file in this.files)
            {
                // Match the file name against the original filter
                FileNameRegex r           = this.regex; // new FileNameRegex(filter);
                string        newFileName = r.ReplaceFileName(file, newNames);
                Console.WriteLine(prefix + file + " --> " + newFileName);
                if (!previewOnly)
                {
                    // Rename baseDir + file to baseDir + newFileName
                    File.Move(baseDir + file, baseDir + newFileName);
                }
            }

            // Handle subdirectories
            foreach (RegExDirInfo dir in this.directories)
            {
                dir.Rename(skipPrefix, newNames, previewOnly);
            }
        }
Пример #2
0
        private void Preview()
        {
            FileNameRegex fnr = new FileNameRegex(this.matchTextBox.Text);

            string replacePattern = this.replaceTextBox.Text;

            // Set up the file list
            this.fileList.Items.Clear();
            // Loop over all file names in the root folder
            foreach (FileItem file in this.rootFolder.Files)
            {
                string oldName = file.Name;
                string newName = fnr.ReplaceFileName(oldName, replacePattern);
                if (newName != null)
                {
                    ListViewItem item = this.fileList.Items.Add(oldName, file.SmallIconIndex);
                    item.SubItems.Add(newName);

                    if (newName != oldName)
                    {
                        item.Checked     = true;
                        item.ToolTipText = newName + " --> " + oldName;
                    }
                    else
                    {
                        item.Checked     = false;
                        item.ToolTipText = oldName;
                    }
                }
            }
        }