FileEx.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. /** @addtogroup Utility
  7. * @{
  8. */
  9. /// <summary>
  10. /// Contains various methods that provide handling for files not provided by System.File type.
  11. /// </summary>
  12. public static class FileEx
  13. {
  14. /// <summary>
  15. /// Moves a file from one path to another, while creating any parent directories if they don't already exist.
  16. /// </summary>
  17. /// <param name="source">Path to the file to move.</param>
  18. /// <param name="destination">New location and/or name of the file.</param>
  19. public static void Move(string source, string destination)
  20. {
  21. string destParent = PathEx.GetParent(destination);
  22. if (!string.IsNullOrEmpty(destParent))
  23. {
  24. if (!Directory.Exists(destParent))
  25. Directory.CreateDirectory(destParent);
  26. }
  27. File.Move(source, destination);
  28. }
  29. /// <summary>
  30. /// Copies a file from one path to another, while creating any parent directories if they don't already exist.
  31. /// </summary>
  32. /// <param name="source">Path to the file to copy.</param>
  33. /// <param name="destination">Path to the copied file.</param>
  34. public static void Copy(string source, string destination)
  35. {
  36. string destParent = PathEx.GetParent(destination);
  37. if (!string.IsNullOrEmpty(destParent))
  38. {
  39. if (!Directory.Exists(destParent))
  40. Directory.CreateDirectory(destParent);
  41. }
  42. File.Copy(source, destination);
  43. }
  44. }
  45. /** @} */
  46. }