FileEx.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System.IO;
  4. namespace BansheeEngine
  5. {
  6. /// <summary>
  7. /// Contains various methods that provide handling for files not provided by System.File type.
  8. /// </summary>
  9. public static class FileEx
  10. {
  11. /// <summary>
  12. /// Moves a file from one path to another, while creating any parent directories if they don't already exist.
  13. /// </summary>
  14. /// <param name="source">Path to the file to move.</param>
  15. /// <param name="destination">New location and/or name of the file.</param>
  16. public static void Move(string source, string destination)
  17. {
  18. string destParent = PathEx.GetParent(destination);
  19. if (!string.IsNullOrEmpty(destParent))
  20. {
  21. if (!Directory.Exists(destParent))
  22. Directory.CreateDirectory(destParent);
  23. }
  24. File.Move(source, destination);
  25. }
  26. /// <summary>
  27. /// Copies a file from one path to another, while creating any parent directories if they don't already exist.
  28. /// </summary>
  29. /// <param name="source">Path to the file to copy.</param>
  30. /// <param name="destination">Path to the copied file.</param>
  31. public static void Copy(string source, string destination)
  32. {
  33. string destParent = PathEx.GetParent(destination);
  34. if (!string.IsNullOrEmpty(destParent))
  35. {
  36. if (!Directory.Exists(destParent))
  37. Directory.CreateDirectory(destParent);
  38. }
  39. File.Copy(source, destination);
  40. }
  41. }
  42. }