ManagedFileSystem.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using MediaBrowser.Model.IO;
  7. using MediaBrowser.Model.Logging;
  8. namespace MediaBrowser.Common.Implementations.IO
  9. {
  10. /// <summary>
  11. /// Class ManagedFileSystem
  12. /// </summary>
  13. public class ManagedFileSystem : IFileSystem
  14. {
  15. protected ILogger Logger;
  16. private readonly bool _supportsAsyncFileStreams;
  17. private char[] _invalidFileNameChars;
  18. private readonly List<IShortcutHandler> _shortcutHandlers = new List<IShortcutHandler>();
  19. protected bool EnableFileSystemRequestConcat = true;
  20. public ManagedFileSystem(ILogger logger, bool supportsAsyncFileStreams, bool enableManagedInvalidFileNameChars)
  21. {
  22. Logger = logger;
  23. _supportsAsyncFileStreams = supportsAsyncFileStreams;
  24. SetInvalidFileNameChars(enableManagedInvalidFileNameChars);
  25. }
  26. public void AddShortcutHandler(IShortcutHandler handler)
  27. {
  28. _shortcutHandlers.Add(handler);
  29. }
  30. protected void SetInvalidFileNameChars(bool enableManagedInvalidFileNameChars)
  31. {
  32. if (enableManagedInvalidFileNameChars)
  33. {
  34. _invalidFileNameChars = Path.GetInvalidFileNameChars();
  35. }
  36. else
  37. {
  38. // GetInvalidFileNameChars is less restrictive in Linux/Mac than Windows, this mimic Windows behavior for mono under Linux/Mac.
  39. _invalidFileNameChars = new char[41] { '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07',
  40. '\x08', '\x09', '\x0A', '\x0B', '\x0C', '\x0D', '\x0E', '\x0F', '\x10', '\x11', '\x12',
  41. '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1A', '\x1B', '\x1C', '\x1D',
  42. '\x1E', '\x1F', '\x22', '\x3C', '\x3E', '\x7C', ':', '*', '?', '\\', '/' };
  43. }
  44. }
  45. public char DirectorySeparatorChar
  46. {
  47. get
  48. {
  49. return Path.DirectorySeparatorChar;
  50. }
  51. }
  52. public string GetFullPath(string path)
  53. {
  54. return Path.GetFullPath(path);
  55. }
  56. /// <summary>
  57. /// Determines whether the specified filename is shortcut.
  58. /// </summary>
  59. /// <param name="filename">The filename.</param>
  60. /// <returns><c>true</c> if the specified filename is shortcut; otherwise, <c>false</c>.</returns>
  61. /// <exception cref="System.ArgumentNullException">filename</exception>
  62. public virtual bool IsShortcut(string filename)
  63. {
  64. if (string.IsNullOrEmpty(filename))
  65. {
  66. throw new ArgumentNullException("filename");
  67. }
  68. var extension = Path.GetExtension(filename);
  69. return _shortcutHandlers.Any(i => string.Equals(extension, i.Extension, StringComparison.OrdinalIgnoreCase));
  70. }
  71. /// <summary>
  72. /// Resolves the shortcut.
  73. /// </summary>
  74. /// <param name="filename">The filename.</param>
  75. /// <returns>System.String.</returns>
  76. /// <exception cref="System.ArgumentNullException">filename</exception>
  77. public virtual string ResolveShortcut(string filename)
  78. {
  79. if (string.IsNullOrEmpty(filename))
  80. {
  81. throw new ArgumentNullException("filename");
  82. }
  83. var extension = Path.GetExtension(filename);
  84. var handler = _shortcutHandlers.FirstOrDefault(i => string.Equals(extension, i.Extension, StringComparison.OrdinalIgnoreCase));
  85. if (handler != null)
  86. {
  87. return handler.Resolve(filename);
  88. }
  89. return null;
  90. }
  91. /// <summary>
  92. /// Creates the shortcut.
  93. /// </summary>
  94. /// <param name="shortcutPath">The shortcut path.</param>
  95. /// <param name="target">The target.</param>
  96. /// <exception cref="System.ArgumentNullException">
  97. /// shortcutPath
  98. /// or
  99. /// target
  100. /// </exception>
  101. public void CreateShortcut(string shortcutPath, string target)
  102. {
  103. if (string.IsNullOrEmpty(shortcutPath))
  104. {
  105. throw new ArgumentNullException("shortcutPath");
  106. }
  107. if (string.IsNullOrEmpty(target))
  108. {
  109. throw new ArgumentNullException("target");
  110. }
  111. var extension = Path.GetExtension(shortcutPath);
  112. var handler = _shortcutHandlers.FirstOrDefault(i => string.Equals(extension, i.Extension, StringComparison.OrdinalIgnoreCase));
  113. if (handler != null)
  114. {
  115. handler.Create(shortcutPath, target);
  116. }
  117. else
  118. {
  119. throw new NotImplementedException();
  120. }
  121. }
  122. /// <summary>
  123. /// Returns a <see cref="FileSystemMetadata"/> object for the specified file or directory path.
  124. /// </summary>
  125. /// <param name="path">A path to a file or directory.</param>
  126. /// <returns>A <see cref="FileSystemMetadata"/> object.</returns>
  127. /// <remarks>If the specified path points to a directory, the returned <see cref="FileSystemMetadata"/> object's
  128. /// <see cref="FileSystemMetadata.IsDirectory"/> property will be set to true and all other properties will reflect the properties of the directory.</remarks>
  129. public FileSystemMetadata GetFileSystemInfo(string path)
  130. {
  131. if (string.IsNullOrEmpty(path))
  132. {
  133. throw new ArgumentNullException("path");
  134. }
  135. // Take a guess to try and avoid two file system hits, but we'll double-check by calling Exists
  136. if (Path.HasExtension(path))
  137. {
  138. var fileInfo = new FileInfo(path);
  139. if (fileInfo.Exists)
  140. {
  141. return GetFileSystemMetadata(fileInfo);
  142. }
  143. return GetFileSystemMetadata(new DirectoryInfo(path));
  144. }
  145. else
  146. {
  147. var fileInfo = new DirectoryInfo(path);
  148. if (fileInfo.Exists)
  149. {
  150. return GetFileSystemMetadata(fileInfo);
  151. }
  152. return GetFileSystemMetadata(new FileInfo(path));
  153. }
  154. }
  155. /// <summary>
  156. /// Returns a <see cref="FileSystemMetadata"/> object for the specified file path.
  157. /// </summary>
  158. /// <param name="path">A path to a file.</param>
  159. /// <returns>A <see cref="FileSystemMetadata"/> object.</returns>
  160. /// <remarks><para>If the specified path points to a directory, the returned <see cref="FileSystemMetadata"/> object's
  161. /// <see cref="FileSystemMetadata.IsDirectory"/> property and the <see cref="FileSystemMetadata.Exists"/> property will both be set to false.</para>
  162. /// <para>For automatic handling of files <b>and</b> directories, use <see cref="GetFileSystemInfo"/>.</para></remarks>
  163. public FileSystemMetadata GetFileInfo(string path)
  164. {
  165. if (string.IsNullOrEmpty(path))
  166. {
  167. throw new ArgumentNullException("path");
  168. }
  169. var fileInfo = new FileInfo(path);
  170. return GetFileSystemMetadata(fileInfo);
  171. }
  172. /// <summary>
  173. /// Returns a <see cref="FileSystemMetadata"/> object for the specified directory path.
  174. /// </summary>
  175. /// <param name="path">A path to a directory.</param>
  176. /// <returns>A <see cref="FileSystemMetadata"/> object.</returns>
  177. /// <remarks><para>If the specified path points to a file, the returned <see cref="FileSystemMetadata"/> object's
  178. /// <see cref="FileSystemMetadata.IsDirectory"/> property will be set to true and the <see cref="FileSystemMetadata.Exists"/> property will be set to false.</para>
  179. /// <para>For automatic handling of files <b>and</b> directories, use <see cref="GetFileSystemInfo"/>.</para></remarks>
  180. public FileSystemMetadata GetDirectoryInfo(string path)
  181. {
  182. if (string.IsNullOrEmpty(path))
  183. {
  184. throw new ArgumentNullException("path");
  185. }
  186. var fileInfo = new DirectoryInfo(path);
  187. return GetFileSystemMetadata(fileInfo);
  188. }
  189. private FileSystemMetadata GetFileSystemMetadata(FileSystemInfo info)
  190. {
  191. var result = new FileSystemMetadata();
  192. result.Exists = info.Exists;
  193. result.FullName = info.FullName;
  194. result.Extension = info.Extension;
  195. result.Name = info.Name;
  196. if (result.Exists)
  197. {
  198. var attributes = info.Attributes;
  199. result.IsDirectory = info is DirectoryInfo || (attributes & FileAttributes.Directory) == FileAttributes.Directory;
  200. result.IsHidden = (attributes & FileAttributes.Hidden) == FileAttributes.Hidden;
  201. result.IsReadOnly = (attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly;
  202. var fileInfo = info as FileInfo;
  203. if (fileInfo != null)
  204. {
  205. result.Length = fileInfo.Length;
  206. result.DirectoryName = fileInfo.DirectoryName;
  207. }
  208. result.CreationTimeUtc = GetCreationTimeUtc(info);
  209. result.LastWriteTimeUtc = GetLastWriteTimeUtc(info);
  210. }
  211. else
  212. {
  213. result.IsDirectory = info is DirectoryInfo;
  214. }
  215. return result;
  216. }
  217. /// <summary>
  218. /// The space char
  219. /// </summary>
  220. private const char SpaceChar = ' ';
  221. /// <summary>
  222. /// Takes a filename and removes invalid characters
  223. /// </summary>
  224. /// <param name="filename">The filename.</param>
  225. /// <returns>System.String.</returns>
  226. /// <exception cref="System.ArgumentNullException">filename</exception>
  227. public string GetValidFilename(string filename)
  228. {
  229. if (string.IsNullOrEmpty(filename))
  230. {
  231. throw new ArgumentNullException("filename");
  232. }
  233. var builder = new StringBuilder(filename);
  234. foreach (var c in _invalidFileNameChars)
  235. {
  236. builder = builder.Replace(c, SpaceChar);
  237. }
  238. return builder.ToString();
  239. }
  240. /// <summary>
  241. /// Gets the creation time UTC.
  242. /// </summary>
  243. /// <param name="info">The info.</param>
  244. /// <returns>DateTime.</returns>
  245. public DateTime GetCreationTimeUtc(FileSystemInfo info)
  246. {
  247. // This could throw an error on some file systems that have dates out of range
  248. try
  249. {
  250. return info.CreationTimeUtc;
  251. }
  252. catch (Exception ex)
  253. {
  254. Logger.ErrorException("Error determining CreationTimeUtc for {0}", ex, info.FullName);
  255. return DateTime.MinValue;
  256. }
  257. }
  258. /// <summary>
  259. /// Gets the creation time UTC.
  260. /// </summary>
  261. /// <param name="path">The path.</param>
  262. /// <returns>DateTime.</returns>
  263. public DateTime GetCreationTimeUtc(string path)
  264. {
  265. return GetCreationTimeUtc(GetFileSystemInfo(path));
  266. }
  267. public DateTime GetCreationTimeUtc(FileSystemMetadata info)
  268. {
  269. return info.CreationTimeUtc;
  270. }
  271. public DateTime GetLastWriteTimeUtc(FileSystemMetadata info)
  272. {
  273. return info.LastWriteTimeUtc;
  274. }
  275. /// <summary>
  276. /// Gets the creation time UTC.
  277. /// </summary>
  278. /// <param name="info">The info.</param>
  279. /// <returns>DateTime.</returns>
  280. public DateTime GetLastWriteTimeUtc(FileSystemInfo info)
  281. {
  282. // This could throw an error on some file systems that have dates out of range
  283. try
  284. {
  285. return info.LastWriteTimeUtc;
  286. }
  287. catch (Exception ex)
  288. {
  289. Logger.ErrorException("Error determining LastAccessTimeUtc for {0}", ex, info.FullName);
  290. return DateTime.MinValue;
  291. }
  292. }
  293. /// <summary>
  294. /// Gets the last write time UTC.
  295. /// </summary>
  296. /// <param name="path">The path.</param>
  297. /// <returns>DateTime.</returns>
  298. public DateTime GetLastWriteTimeUtc(string path)
  299. {
  300. return GetLastWriteTimeUtc(GetFileSystemInfo(path));
  301. }
  302. /// <summary>
  303. /// Gets the file stream.
  304. /// </summary>
  305. /// <param name="path">The path.</param>
  306. /// <param name="mode">The mode.</param>
  307. /// <param name="access">The access.</param>
  308. /// <param name="share">The share.</param>
  309. /// <param name="isAsync">if set to <c>true</c> [is asynchronous].</param>
  310. /// <returns>FileStream.</returns>
  311. public Stream GetFileStream(string path, FileOpenMode mode, FileAccessMode access, FileShareMode share, bool isAsync = false)
  312. {
  313. if (_supportsAsyncFileStreams && isAsync)
  314. {
  315. return new FileStream(path, GetFileMode(mode), GetFileAccess(access), GetFileShare(share), 262144, true);
  316. }
  317. return new FileStream(path, GetFileMode(mode), GetFileAccess(access), GetFileShare(share), 262144);
  318. }
  319. private FileMode GetFileMode(FileOpenMode mode)
  320. {
  321. switch (mode)
  322. {
  323. case FileOpenMode.Append:
  324. return FileMode.Append;
  325. case FileOpenMode.Create:
  326. return FileMode.Create;
  327. case FileOpenMode.CreateNew:
  328. return FileMode.CreateNew;
  329. case FileOpenMode.Open:
  330. return FileMode.Open;
  331. case FileOpenMode.OpenOrCreate:
  332. return FileMode.OpenOrCreate;
  333. case FileOpenMode.Truncate:
  334. return FileMode.Truncate;
  335. default:
  336. throw new Exception("Unrecognized FileOpenMode");
  337. }
  338. }
  339. private FileAccess GetFileAccess(FileAccessMode mode)
  340. {
  341. var val = (int)mode;
  342. return (FileAccess)val;
  343. }
  344. private FileShare GetFileShare(FileShareMode mode)
  345. {
  346. var val = (int)mode;
  347. return (FileShare)val;
  348. }
  349. public void SetHidden(string path, bool isHidden)
  350. {
  351. var info = GetFileInfo(path);
  352. if (info.Exists && info.IsHidden != isHidden)
  353. {
  354. if (isHidden)
  355. {
  356. FileAttributes attributes = File.GetAttributes(path);
  357. attributes = RemoveAttribute(attributes, FileAttributes.Hidden);
  358. File.SetAttributes(path, attributes);
  359. }
  360. else
  361. {
  362. File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden);
  363. }
  364. }
  365. }
  366. private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove)
  367. {
  368. return attributes & ~attributesToRemove;
  369. }
  370. /// <summary>
  371. /// Swaps the files.
  372. /// </summary>
  373. /// <param name="file1">The file1.</param>
  374. /// <param name="file2">The file2.</param>
  375. public void SwapFiles(string file1, string file2)
  376. {
  377. if (string.IsNullOrEmpty(file1))
  378. {
  379. throw new ArgumentNullException("file1");
  380. }
  381. if (string.IsNullOrEmpty(file2))
  382. {
  383. throw new ArgumentNullException("file2");
  384. }
  385. var temp1 = Path.GetTempFileName();
  386. var temp2 = Path.GetTempFileName();
  387. // Copying over will fail against hidden files
  388. RemoveHiddenAttribute(file1);
  389. RemoveHiddenAttribute(file2);
  390. CopyFile(file1, temp1, true);
  391. CopyFile(file2, temp2, true);
  392. CopyFile(temp1, file2, true);
  393. CopyFile(temp2, file1, true);
  394. DeleteFile(temp1);
  395. DeleteFile(temp2);
  396. }
  397. /// <summary>
  398. /// Removes the hidden attribute.
  399. /// </summary>
  400. /// <param name="path">The path.</param>
  401. private void RemoveHiddenAttribute(string path)
  402. {
  403. if (string.IsNullOrEmpty(path))
  404. {
  405. throw new ArgumentNullException("path");
  406. }
  407. var currentFile = new FileInfo(path);
  408. // This will fail if the file is hidden
  409. if (currentFile.Exists)
  410. {
  411. if ((currentFile.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
  412. {
  413. currentFile.Attributes &= ~FileAttributes.Hidden;
  414. }
  415. }
  416. }
  417. public bool ContainsSubPath(string parentPath, string path)
  418. {
  419. if (string.IsNullOrEmpty(parentPath))
  420. {
  421. throw new ArgumentNullException("parentPath");
  422. }
  423. if (string.IsNullOrEmpty(path))
  424. {
  425. throw new ArgumentNullException("path");
  426. }
  427. return path.IndexOf(parentPath.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase) != -1;
  428. }
  429. public bool IsRootPath(string path)
  430. {
  431. if (string.IsNullOrEmpty(path))
  432. {
  433. throw new ArgumentNullException("path");
  434. }
  435. var parent = Path.GetDirectoryName(path);
  436. if (!string.IsNullOrEmpty(parent))
  437. {
  438. return false;
  439. }
  440. return true;
  441. }
  442. public string NormalizePath(string path)
  443. {
  444. if (string.IsNullOrEmpty(path))
  445. {
  446. throw new ArgumentNullException("path");
  447. }
  448. if (path.EndsWith(":\\", StringComparison.OrdinalIgnoreCase))
  449. {
  450. return path;
  451. }
  452. return path.TrimEnd(Path.DirectorySeparatorChar);
  453. }
  454. public string GetFileNameWithoutExtension(FileSystemMetadata info)
  455. {
  456. if (info.IsDirectory)
  457. {
  458. return info.Name;
  459. }
  460. return Path.GetFileNameWithoutExtension(info.FullName);
  461. }
  462. public string GetFileNameWithoutExtension(string path)
  463. {
  464. return Path.GetFileNameWithoutExtension(path);
  465. }
  466. public bool IsPathFile(string path)
  467. {
  468. if (string.IsNullOrWhiteSpace(path))
  469. {
  470. throw new ArgumentNullException("path");
  471. }
  472. // Cannot use Path.IsPathRooted because it returns false under mono when using windows-based paths, e.g. C:\\
  473. if (path.IndexOf("://", StringComparison.OrdinalIgnoreCase) != -1 &&
  474. !path.StartsWith("file://", StringComparison.OrdinalIgnoreCase))
  475. {
  476. return false;
  477. }
  478. return true;
  479. //return Path.IsPathRooted(path);
  480. }
  481. public void DeleteFile(string path)
  482. {
  483. File.Delete(path);
  484. }
  485. public void DeleteDirectory(string path, bool recursive)
  486. {
  487. Directory.Delete(path, recursive);
  488. }
  489. public void CreateDirectory(string path)
  490. {
  491. Directory.CreateDirectory(path);
  492. }
  493. public IEnumerable<FileSystemMetadata> GetDirectories(string path, bool recursive = false)
  494. {
  495. var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
  496. return ToMetadata(path, new DirectoryInfo(path).EnumerateDirectories("*", searchOption));
  497. }
  498. public IEnumerable<FileSystemMetadata> GetFiles(string path, bool recursive = false)
  499. {
  500. var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
  501. return ToMetadata(path, new DirectoryInfo(path).EnumerateFiles("*", searchOption));
  502. }
  503. public IEnumerable<FileSystemMetadata> GetFileSystemEntries(string path, bool recursive = false)
  504. {
  505. var directoryInfo = new DirectoryInfo(path);
  506. var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
  507. if (EnableFileSystemRequestConcat)
  508. {
  509. return ToMetadata(path, directoryInfo.EnumerateDirectories("*", searchOption))
  510. .Concat(ToMetadata(path, directoryInfo.EnumerateFiles("*", searchOption)));
  511. }
  512. return ToMetadata(path, directoryInfo.EnumerateFileSystemInfos("*", searchOption));
  513. }
  514. private IEnumerable<FileSystemMetadata> ToMetadata(string parentPath, IEnumerable<FileSystemInfo> infos)
  515. {
  516. return infos.Select(i =>
  517. {
  518. try
  519. {
  520. return GetFileSystemMetadata(i);
  521. }
  522. catch (PathTooLongException)
  523. {
  524. // Can't log using the FullName because it will throw the PathTooLongExceptiona again
  525. //Logger.Warn("Path too long: {0}", i.FullName);
  526. Logger.Warn("File or directory path too long. Parent folder: {0}", parentPath);
  527. return null;
  528. }
  529. }).Where(i => i != null);
  530. }
  531. public Stream OpenRead(string path)
  532. {
  533. return File.OpenRead(path);
  534. }
  535. public void CopyFile(string source, string target, bool overwrite)
  536. {
  537. File.Copy(source, target, overwrite);
  538. }
  539. public void MoveFile(string source, string target)
  540. {
  541. File.Move(source, target);
  542. }
  543. public void MoveDirectory(string source, string target)
  544. {
  545. Directory.Move(source, target);
  546. }
  547. public bool DirectoryExists(string path)
  548. {
  549. return Directory.Exists(path);
  550. }
  551. public bool FileExists(string path)
  552. {
  553. return File.Exists(path);
  554. }
  555. public string ReadAllText(string path)
  556. {
  557. return File.ReadAllText(path);
  558. }
  559. public byte[] ReadAllBytes(string path)
  560. {
  561. return File.ReadAllBytes(path);
  562. }
  563. public void WriteAllText(string path, string text, Encoding encoding)
  564. {
  565. File.WriteAllText(path, text, encoding);
  566. }
  567. public void WriteAllText(string path, string text)
  568. {
  569. File.WriteAllText(path, text);
  570. }
  571. public void WriteAllBytes(string path, byte[] bytes)
  572. {
  573. File.WriteAllBytes(path, bytes);
  574. }
  575. public string ReadAllText(string path, Encoding encoding)
  576. {
  577. return File.ReadAllText(path, encoding);
  578. }
  579. public IEnumerable<string> GetDirectoryPaths(string path, bool recursive = false)
  580. {
  581. var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
  582. return Directory.EnumerateDirectories(path, "*", searchOption);
  583. }
  584. public IEnumerable<string> GetFilePaths(string path, bool recursive = false)
  585. {
  586. var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
  587. return Directory.EnumerateFiles(path, "*", searchOption);
  588. }
  589. public IEnumerable<string> GetFileSystemEntryPaths(string path, bool recursive = false)
  590. {
  591. var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
  592. return Directory.EnumerateFileSystemEntries(path, "*", searchOption);
  593. }
  594. }
  595. }