ManagedFileSystem.cs 24 KB

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