You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.9 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Apewer.Run
  8. {
  9. class FileRenamer
  10. {
  11. public FileRenamer()
  12. {
  13. // RenameZQSV();
  14. var dir = @"E:\Breaking Bad";
  15. var paths = StorageUtility.GetSubFiles(dir, true);
  16. var array = Json.NewArray();
  17. foreach (var path in paths)
  18. {
  19. var name = Path.GetFileName(path);
  20. if (name.EndsWith(".mkv")) continue;
  21. if (name.EndsWith(".json")) continue;
  22. name = name.Replace("Breaking Bad - ", "");
  23. array.AddItem(name);
  24. name = name + ".srt";
  25. var newPath = Path.Combine(Path.GetDirectoryName(path), name);
  26. if (newPath != path)
  27. {
  28. File.Move(path, newPath);
  29. Console.WriteLine($"{path} -> {newPath}");
  30. }
  31. // else Console.WriteLine(path);
  32. }
  33. StorageUtility.WriteFile(Path.Combine(dir, "info.json"), array.ToString(true).ToBinary());
  34. }
  35. void RenameZQSV()
  36. {
  37. var paths = Apewer.StorageUtility.GetSubFiles("z:\\", true);
  38. foreach (var path in paths)
  39. {
  40. RenameFile(path, " ", "_");
  41. RenameFile(path, "【蓝光1080P】", "");
  42. }
  43. }
  44. void RenameFile(string path, string oldSub, string newSub)
  45. {
  46. if (path.Contains(oldSub))
  47. {
  48. var newName = path.Replace(oldSub, newSub);
  49. File.Move(path, newName);
  50. Console.WriteLine($"{path} -> {newName}");
  51. }
  52. else
  53. {
  54. Console.WriteLine(path);
  55. }
  56. }
  57. }
  58. }