2
0

FileEx.cs 1.6 KB

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