Пример #1
0
 /// <summary>
 /// Abstract method to rename private field <see cref="Music.name"/>
 /// </summary>
 /// <remarks>
 /// See <see cref="Song.Flatten()"/> and <see cref="Release.Flatten()"/> for implementation.
 /// </remarks>
 public virtual void Rename(Renamer renamer)
 {
   Name = renamer.Rename(this);
   if (Formatter != null)
   {
     Name = Formatter.Format(FileType, Name);
   }
   string NewPath = Parent.Path + "\\" + Name + Extension;
   System.IO.File.Move(Path, NewPath);
   Path = NewPath;
 }
Пример #2
0
    /// <summary>
    /// Renames children objects physical files with string
    /// stored in associated Name field.
    /// </summary>
    /// <remarks>
    /// Children objects are renamed first followed by the current object
    /// to avoid <see cref="FileNotFoundException"/>
    /// </remarks>
    public override void Rename(Renamer renamer)
    {
      Trace.WriteLine("Renaming album " + Name);

      // Apply child renaming
      foreach (File child in children)
      {
         child.Rename(renamer);
      }

      // Re-apply any formatting after rename
      Name = renamer.Rename(this);
      if (Formatter != null)
      {
        Name = Formatter.Format(FileType, Name);
      }

      // Case-sensitive based renames fail under Windows. Workaround,
      // First change name by appending character, then rename to new name with 
      // corrected case.
      string NewPath = Parent.Path + "\\" + Name + "_";
      System.IO.Directory.Move(Path, NewPath);
      System.IO.Directory.Move(NewPath, NewPath.TrimEnd(new char[] { '_' }));
    }