mscorlib(4.0.0.0) API with additions
Directory.cs
1 using Microsoft.Win32;
2 using Microsoft.Win32.SafeHandles;
5 using System.Security;
8 using System.Text;
9 
10 namespace System.IO
11 {
13  [ComVisible(true)]
14  public static class Directory
15  {
16  internal sealed class SearchData
17  {
18  public readonly string fullPath;
19 
20  public readonly string userPath;
21 
22  public readonly SearchOption searchOption;
23 
24  public SearchData(string fullPath, string userPath, SearchOption searchOption)
25  {
26  this.fullPath = fullPath;
27  this.userPath = userPath;
28  this.searchOption = searchOption;
29  }
30  }
31 
32  private const int FILE_ATTRIBUTE_DIRECTORY = 16;
33 
34  private const int GENERIC_WRITE = 1073741824;
35 
36  private const int FILE_SHARE_WRITE = 2;
37 
38  private const int FILE_SHARE_DELETE = 4;
39 
40  private const int OPEN_EXISTING = 3;
41 
42  private const int FILE_FLAG_BACKUP_SEMANTICS = 33554432;
43 
55  public static DirectoryInfo GetParent(string path)
56  {
57  if (path == null)
58  {
59  throw new ArgumentNullException("path");
60  }
61  if (path.Length == 0)
62  {
63  throw new ArgumentException(Environment.GetResourceString("Argument_PathEmpty"), "path");
64  }
65  string fullPathInternal = Path.GetFullPathInternal(path);
66  string directoryName = Path.GetDirectoryName(fullPathInternal);
67  if (directoryName == null)
68  {
69  return null;
70  }
71  return new DirectoryInfo(directoryName);
72  }
73 
88  [SecuritySafeCritical]
89  public static DirectoryInfo CreateDirectory(string path)
90  {
91  if (path == null)
92  {
93  throw new ArgumentNullException("path");
94  }
95  if (path.Length == 0)
96  {
97  throw new ArgumentException(Environment.GetResourceString("Argument_PathEmpty"));
98  }
99  return InternalCreateDirectoryHelper(path, checkHost: true);
100  }
101 
102  [SecurityCritical]
103  internal static DirectoryInfo UnsafeCreateDirectory(string path)
104  {
105  if (path == null)
106  {
107  throw new ArgumentNullException("path");
108  }
109  if (path.Length == 0)
110  {
111  throw new ArgumentException(Environment.GetResourceString("Argument_PathEmpty"));
112  }
113  return InternalCreateDirectoryHelper(path, checkHost: false);
114  }
115 
116  [SecurityCritical]
117  internal static DirectoryInfo InternalCreateDirectoryHelper(string path, bool checkHost)
118  {
119  string fullPathAndCheckPermissions = GetFullPathAndCheckPermissions(path, checkHost);
120  InternalCreateDirectory(fullPathAndCheckPermissions, path, null, checkHost);
121  return new DirectoryInfo(fullPathAndCheckPermissions, junk: false);
122  }
123 
124  internal static string GetFullPathAndCheckPermissions(string path, bool checkHost, FileSecurityStateAccess access = FileSecurityStateAccess.Read)
125  {
126  string fullPathInternal = Path.GetFullPathInternal(path);
127  CheckPermissions(path, fullPathInternal, checkHost, access);
128  return fullPathInternal;
129  }
130 
131  [SecuritySafeCritical]
132  internal static void CheckPermissions(string displayPath, string fullPath, bool checkHost, FileSecurityStateAccess access = FileSecurityStateAccess.Read)
133  {
134  if (CodeAccessSecurityEngine.QuickCheckForAllDemands())
135  {
136  FileIOPermission.EmulateFileIOPermissionChecks(fullPath);
137  }
138  else
139  {
140  FileIOPermission.QuickDemand((FileIOPermissionAccess)access, GetDemandDir(fullPath, thisDirOnly: true), checkForDuplicates: false, needFullPath: false);
141  }
142  }
143 
159  [SecuritySafeCritical]
160  public static DirectoryInfo CreateDirectory(string path, DirectorySecurity directorySecurity)
161  {
162  if (path == null)
163  {
164  throw new ArgumentNullException("path");
165  }
166  if (path.Length == 0)
167  {
168  throw new ArgumentException(Environment.GetResourceString("Argument_PathEmpty"));
169  }
170  string fullPathAndCheckPermissions = GetFullPathAndCheckPermissions(path, checkHost: true);
171  InternalCreateDirectory(fullPathAndCheckPermissions, path, directorySecurity);
172  return new DirectoryInfo(fullPathAndCheckPermissions, junk: false);
173  }
174 
175  internal static string GetDemandDir(string fullPath, bool thisDirOnly)
176  {
177  if (thisDirOnly)
178  {
179  if (fullPath.EndsWith(Path.DirectorySeparatorChar) || fullPath.EndsWith(Path.AltDirectorySeparatorChar))
180  {
181  return fullPath + ".";
182  }
183  return fullPath + "\\.";
184  }
185  if (!fullPath.EndsWith(Path.DirectorySeparatorChar) && !fullPath.EndsWith(Path.AltDirectorySeparatorChar))
186  {
187  return fullPath + "\\";
188  }
189  return fullPath;
190  }
191 
192  internal static void InternalCreateDirectory(string fullPath, string path, object dirSecurityObj)
193  {
194  InternalCreateDirectory(fullPath, path, dirSecurityObj, checkHost: false);
195  }
196 
197  [SecuritySafeCritical]
198  internal unsafe static void InternalCreateDirectory(string fullPath, string path, object dirSecurityObj, bool checkHost)
199  {
200  DirectorySecurity directorySecurity = (DirectorySecurity)dirSecurityObj;
201  int num = fullPath.Length;
202  if (num >= 2 && Path.IsDirectorySeparator(fullPath[num - 1]))
203  {
204  num--;
205  }
206  int rootLength = Path.GetRootLength(fullPath);
207  if (num == 2 && Path.IsDirectorySeparator(fullPath[1]))
208  {
209  throw new IOException(Environment.GetResourceString("IO.IO_CannotCreateDirectory", path));
210  }
211  if (InternalExists(fullPath))
212  {
213  return;
214  }
215  List<string> list = new List<string>();
216  bool flag = false;
217  if (num > rootLength)
218  {
219  int num2 = num - 1;
220  while (num2 >= rootLength && !flag)
221  {
222  string text = fullPath.Substring(0, num2 + 1);
223  if (!InternalExists(text))
224  {
225  list.Add(text);
226  }
227  else
228  {
229  flag = true;
230  }
231  while (num2 > rootLength && fullPath[num2] != Path.DirectorySeparatorChar && fullPath[num2] != Path.AltDirectorySeparatorChar)
232  {
233  num2--;
234  }
235  num2--;
236  }
237  }
238  int count = list.Count;
239  if (list.Count != 0 && !CodeAccessSecurityEngine.QuickCheckForAllDemands())
240  {
241  string[] array = new string[list.Count];
242  list.CopyTo(array, 0);
243  for (int i = 0; i < array.Length; i++)
244  {
245  array[i] += "\\.";
246  }
247  AccessControlActions control = (directorySecurity != null) ? AccessControlActions.Change : AccessControlActions.None;
248  FileIOPermission.QuickDemand(FileIOPermissionAccess.Write, control, array, checkForDuplicates: false, needFullPath: false);
249  }
250  Win32Native.SECURITY_ATTRIBUTES sECURITY_ATTRIBUTES = null;
251  if (directorySecurity != null)
252  {
253  sECURITY_ATTRIBUTES = new Win32Native.SECURITY_ATTRIBUTES();
254  sECURITY_ATTRIBUTES.nLength = Marshal.SizeOf(sECURITY_ATTRIBUTES);
255  byte[] securityDescriptorBinaryForm = directorySecurity.GetSecurityDescriptorBinaryForm();
256  byte* ptr = stackalloc byte[(int)checked(unchecked((ulong)(uint)securityDescriptorBinaryForm.Length) * 1uL)];
257  Buffer.Memcpy(ptr, 0, securityDescriptorBinaryForm, 0, securityDescriptorBinaryForm.Length);
258  sECURITY_ATTRIBUTES.pSecurityDescriptor = ptr;
259  }
260  bool flag2 = true;
261  int num3 = 0;
262  string maybeFullPath = path;
263  while (list.Count > 0)
264  {
265  string text2 = list[list.Count - 1];
266  list.RemoveAt(list.Count - 1);
267  if (PathInternal.IsDirectoryTooLong(text2))
268  {
269  throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong"));
270  }
271  flag2 = Win32Native.CreateDirectory(text2, sECURITY_ATTRIBUTES);
272  if (!flag2 && num3 == 0)
273  {
274  int lastError = Marshal.GetLastWin32Error();
275  if (lastError != 183)
276  {
277  num3 = lastError;
278  }
279  else if (File.InternalExists(text2) || (!InternalExists(text2, out lastError) && lastError == 5))
280  {
281  num3 = lastError;
282  try
283  {
284  CheckPermissions(string.Empty, text2, checkHost, FileSecurityStateAccess.PathDiscovery);
285  maybeFullPath = text2;
286  }
287  catch (SecurityException)
288  {
289  }
290  }
291  }
292  }
293  if (count == 0 && !flag)
294  {
295  string path2 = InternalGetDirectoryRoot(fullPath);
296  if (!InternalExists(path2))
297  {
298  __Error.WinIOError(3, InternalGetDirectoryRoot(path));
299  }
300  }
301  else if (!flag2 && num3 != 0)
302  {
303  __Error.WinIOError(num3, maybeFullPath);
304  }
305  }
306 
311  [SecuritySafeCritical]
312  public static bool Exists(string path)
313  {
314  return InternalExistsHelper(path, checkHost: true);
315  }
316 
317  [SecurityCritical]
318  internal static bool UnsafeExists(string path)
319  {
320  return InternalExistsHelper(path, checkHost: false);
321  }
322 
323  [SecurityCritical]
324  internal static bool InternalExistsHelper(string path, bool checkHost)
325  {
326  if (path == null || path.Length == 0)
327  {
328  return false;
329  }
330  try
331  {
332  string fullPathAndCheckPermissions = GetFullPathAndCheckPermissions(path, checkHost);
333  return InternalExists(fullPathAndCheckPermissions);
334  }
335  catch (ArgumentException)
336  {
337  }
338  catch (NotSupportedException)
339  {
340  }
341  catch (SecurityException)
342  {
343  }
344  catch (IOException)
345  {
346  }
347  catch (UnauthorizedAccessException)
348  {
349  }
350  return false;
351  }
352 
353  [SecurityCritical]
354  internal static bool InternalExists(string path)
355  {
356  int lastError = 0;
357  return InternalExists(path, out lastError);
358  }
359 
360  [SecurityCritical]
361  internal static bool InternalExists(string path, out int lastError)
362  {
363  Win32Native.WIN32_FILE_ATTRIBUTE_DATA data = default(Win32Native.WIN32_FILE_ATTRIBUTE_DATA);
364  lastError = File.FillAttributeInfo(path, ref data, tryagain: false, returnErrorOnNotFound: true);
365  if (lastError == 0 && data.fileAttributes != -1)
366  {
367  return (data.fileAttributes & 0x10) != 0;
368  }
369  return false;
370  }
371 
385  public static void SetCreationTime(string path, DateTime creationTime)
386  {
387  SetCreationTimeUtc(path, creationTime.ToUniversalTime());
388  }
389 
403  [SecuritySafeCritical]
404  public unsafe static void SetCreationTimeUtc(string path, DateTime creationTimeUtc)
405  {
406  using (SafeFileHandle hFile = OpenHandle(path))
407  {
408  Win32Native.FILE_TIME fILE_TIME = new Win32Native.FILE_TIME(creationTimeUtc.ToFileTimeUtc());
409  if (!Win32Native.SetFileTime(hFile, &fILE_TIME, null, null))
410  {
411  int lastWin32Error = Marshal.GetLastWin32Error();
412  __Error.WinIOError(lastWin32Error, path);
413  }
414  }
415  }
416 
426  public static DateTime GetCreationTime(string path)
427  {
428  return File.GetCreationTime(path);
429  }
430 
440  public static DateTime GetCreationTimeUtc(string path)
441  {
442  return File.GetCreationTimeUtc(path);
443  }
444 
458  public static void SetLastWriteTime(string path, DateTime lastWriteTime)
459  {
460  SetLastWriteTimeUtc(path, lastWriteTime.ToUniversalTime());
461  }
462 
476  [SecuritySafeCritical]
477  public unsafe static void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc)
478  {
479  using (SafeFileHandle hFile = OpenHandle(path))
480  {
481  Win32Native.FILE_TIME fILE_TIME = new Win32Native.FILE_TIME(lastWriteTimeUtc.ToFileTimeUtc());
482  if (!Win32Native.SetFileTime(hFile, null, null, &fILE_TIME))
483  {
484  int lastWin32Error = Marshal.GetLastWin32Error();
485  __Error.WinIOError(lastWin32Error, path);
486  }
487  }
488  }
489 
499  public static DateTime GetLastWriteTime(string path)
500  {
501  return File.GetLastWriteTime(path);
502  }
503 
513  public static DateTime GetLastWriteTimeUtc(string path)
514  {
515  return File.GetLastWriteTimeUtc(path);
516  }
517 
531  public static void SetLastAccessTime(string path, DateTime lastAccessTime)
532  {
533  SetLastAccessTimeUtc(path, lastAccessTime.ToUniversalTime());
534  }
535 
549  [SecuritySafeCritical]
550  public unsafe static void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc)
551  {
552  using (SafeFileHandle hFile = OpenHandle(path))
553  {
554  Win32Native.FILE_TIME fILE_TIME = new Win32Native.FILE_TIME(lastAccessTimeUtc.ToFileTimeUtc());
555  if (!Win32Native.SetFileTime(hFile, null, &fILE_TIME, null))
556  {
557  int lastWin32Error = Marshal.GetLastWin32Error();
558  __Error.WinIOError(lastWin32Error, path);
559  }
560  }
561  }
562 
573  public static DateTime GetLastAccessTime(string path)
574  {
575  return File.GetLastAccessTime(path);
576  }
577 
588  public static DateTime GetLastAccessTimeUtc(string path)
589  {
590  return File.GetLastAccessTimeUtc(path);
591  }
592 
601  public static DirectorySecurity GetAccessControl(string path)
602  {
604  }
605 
615  public static DirectorySecurity GetAccessControl(string path, AccessControlSections includeSections)
616  {
617  return new DirectorySecurity(path, includeSections);
618  }
619 
628  [SecuritySafeCritical]
629  public static void SetAccessControl(string path, DirectorySecurity directorySecurity)
630  {
631  if (directorySecurity == null)
632  {
633  throw new ArgumentNullException("directorySecurity");
634  }
635  string fullPathInternal = Path.GetFullPathInternal(path);
636  directorySecurity.Persist(fullPathInternal);
637  }
638 
651  public static string[] GetFiles(string path)
652  {
653  if (path == null)
654  {
655  throw new ArgumentNullException("path");
656  }
657  return InternalGetFiles(path, "*", SearchOption.TopDirectoryOnly);
658  }
659 
674  public static string[] GetFiles(string path, string searchPattern)
675  {
676  if (path == null)
677  {
678  throw new ArgumentNullException("path");
679  }
680  if (searchPattern == null)
681  {
682  throw new ArgumentNullException("searchPattern");
683  }
684  return InternalGetFiles(path, searchPattern, SearchOption.TopDirectoryOnly);
685  }
686 
704  public static string[] GetFiles(string path, string searchPattern, SearchOption searchOption)
705  {
706  if (path == null)
707  {
708  throw new ArgumentNullException("path");
709  }
710  if (searchPattern == null)
711  {
712  throw new ArgumentNullException("searchPattern");
713  }
714  if (searchOption != 0 && searchOption != SearchOption.AllDirectories)
715  {
716  throw new ArgumentOutOfRangeException("searchOption", Environment.GetResourceString("ArgumentOutOfRange_Enum"));
717  }
718  return InternalGetFiles(path, searchPattern, searchOption);
719  }
720 
721  private static string[] InternalGetFiles(string path, string searchPattern, SearchOption searchOption)
722  {
723  return InternalGetFileDirectoryNames(path, path, searchPattern, includeFiles: true, includeDirs: false, searchOption, checkHost: true);
724  }
725 
726  [SecurityCritical]
727  internal static string[] UnsafeGetFiles(string path, string searchPattern, SearchOption searchOption)
728  {
729  return InternalGetFileDirectoryNames(path, path, searchPattern, includeFiles: true, includeDirs: false, searchOption, checkHost: false);
730  }
731 
744  public static string[] GetDirectories(string path)
745  {
746  if (path == null)
747  {
748  throw new ArgumentNullException("path");
749  }
750  return InternalGetDirectories(path, "*", SearchOption.TopDirectoryOnly);
751  }
752 
767  public static string[] GetDirectories(string path, string searchPattern)
768  {
769  if (path == null)
770  {
771  throw new ArgumentNullException("path");
772  }
773  if (searchPattern == null)
774  {
775  throw new ArgumentNullException("searchPattern");
776  }
777  return InternalGetDirectories(path, searchPattern, SearchOption.TopDirectoryOnly);
778  }
779 
797  public static string[] GetDirectories(string path, string searchPattern, SearchOption searchOption)
798  {
799  if (path == null)
800  {
801  throw new ArgumentNullException("path");
802  }
803  if (searchPattern == null)
804  {
805  throw new ArgumentNullException("searchPattern");
806  }
807  if (searchOption != 0 && searchOption != SearchOption.AllDirectories)
808  {
809  throw new ArgumentOutOfRangeException("searchOption", Environment.GetResourceString("ArgumentOutOfRange_Enum"));
810  }
811  return InternalGetDirectories(path, searchPattern, searchOption);
812  }
813 
814  private static string[] InternalGetDirectories(string path, string searchPattern, SearchOption searchOption)
815  {
816  return InternalGetFileDirectoryNames(path, path, searchPattern, includeFiles: false, includeDirs: true, searchOption, checkHost: true);
817  }
818 
819  [SecurityCritical]
820  internal static string[] UnsafeGetDirectories(string path, string searchPattern, SearchOption searchOption)
821  {
822  return InternalGetFileDirectoryNames(path, path, searchPattern, includeFiles: false, includeDirs: true, searchOption, checkHost: false);
823  }
824 
837  public static string[] GetFileSystemEntries(string path)
838  {
839  if (path == null)
840  {
841  throw new ArgumentNullException("path");
842  }
843  return InternalGetFileSystemEntries(path, "*", SearchOption.TopDirectoryOnly);
844  }
845 
860  public static string[] GetFileSystemEntries(string path, string searchPattern)
861  {
862  if (path == null)
863  {
864  throw new ArgumentNullException("path");
865  }
866  if (searchPattern == null)
867  {
868  throw new ArgumentNullException("searchPattern");
869  }
870  return InternalGetFileSystemEntries(path, searchPattern, SearchOption.TopDirectoryOnly);
871  }
872 
893  public static string[] GetFileSystemEntries(string path, string searchPattern, SearchOption searchOption)
894  {
895  if (path == null)
896  {
897  throw new ArgumentNullException("path");
898  }
899  if (searchPattern == null)
900  {
901  throw new ArgumentNullException("searchPattern");
902  }
903  if (searchOption != 0 && searchOption != SearchOption.AllDirectories)
904  {
905  throw new ArgumentOutOfRangeException("searchOption", Environment.GetResourceString("ArgumentOutOfRange_Enum"));
906  }
907  return InternalGetFileSystemEntries(path, searchPattern, searchOption);
908  }
909 
910  private static string[] InternalGetFileSystemEntries(string path, string searchPattern, SearchOption searchOption)
911  {
912  return InternalGetFileDirectoryNames(path, path, searchPattern, includeFiles: true, includeDirs: true, searchOption, checkHost: true);
913  }
914 
915  internal static string[] InternalGetFileDirectoryNames(string path, string userPathOriginal, string searchPattern, bool includeFiles, bool includeDirs, SearchOption searchOption, bool checkHost)
916  {
917  IEnumerable<string> collection = FileSystemEnumerableFactory.CreateFileNameIterator(path, userPathOriginal, searchPattern, includeFiles, includeDirs, searchOption, checkHost);
918  List<string> list = new List<string>(collection);
919  return list.ToArray();
920  }
921 
936  public static IEnumerable<string> EnumerateDirectories(string path)
937  {
938  if (path == null)
939  {
940  throw new ArgumentNullException("path");
941  }
942  return InternalEnumerateDirectories(path, "*", SearchOption.TopDirectoryOnly);
943  }
944 
962  public static IEnumerable<string> EnumerateDirectories(string path, string searchPattern)
963  {
964  if (path == null)
965  {
966  throw new ArgumentNullException("path");
967  }
968  if (searchPattern == null)
969  {
970  throw new ArgumentNullException("searchPattern");
971  }
972  return InternalEnumerateDirectories(path, searchPattern, SearchOption.TopDirectoryOnly);
973  }
974 
995  public static IEnumerable<string> EnumerateDirectories(string path, string searchPattern, SearchOption searchOption)
996  {
997  if (path == null)
998  {
999  throw new ArgumentNullException("path");
1000  }
1001  if (searchPattern == null)
1002  {
1003  throw new ArgumentNullException("searchPattern");
1004  }
1005  if (searchOption != 0 && searchOption != SearchOption.AllDirectories)
1006  {
1007  throw new ArgumentOutOfRangeException("searchOption", Environment.GetResourceString("ArgumentOutOfRange_Enum"));
1008  }
1009  return InternalEnumerateDirectories(path, searchPattern, searchOption);
1010  }
1011 
1012  private static IEnumerable<string> InternalEnumerateDirectories(string path, string searchPattern, SearchOption searchOption)
1013  {
1014  return EnumerateFileSystemNames(path, searchPattern, searchOption, includeFiles: false, includeDirs: true);
1015  }
1016 
1031  public static IEnumerable<string> EnumerateFiles(string path)
1032  {
1033  if (path == null)
1034  {
1035  throw new ArgumentNullException("path");
1036  }
1037  return InternalEnumerateFiles(path, "*", SearchOption.TopDirectoryOnly);
1038  }
1039 
1057  public static IEnumerable<string> EnumerateFiles(string path, string searchPattern)
1058  {
1059  if (path == null)
1060  {
1061  throw new ArgumentNullException("path");
1062  }
1063  if (searchPattern == null)
1064  {
1065  throw new ArgumentNullException("searchPattern");
1066  }
1067  return InternalEnumerateFiles(path, searchPattern, SearchOption.TopDirectoryOnly);
1068  }
1069 
1090  public static IEnumerable<string> EnumerateFiles(string path, string searchPattern, SearchOption searchOption)
1091  {
1092  if (path == null)
1093  {
1094  throw new ArgumentNullException("path");
1095  }
1096  if (searchPattern == null)
1097  {
1098  throw new ArgumentNullException("searchPattern");
1099  }
1100  if (searchOption != 0 && searchOption != SearchOption.AllDirectories)
1101  {
1102  throw new ArgumentOutOfRangeException("searchOption", Environment.GetResourceString("ArgumentOutOfRange_Enum"));
1103  }
1104  return InternalEnumerateFiles(path, searchPattern, searchOption);
1105  }
1106 
1107  private static IEnumerable<string> InternalEnumerateFiles(string path, string searchPattern, SearchOption searchOption)
1108  {
1109  return EnumerateFileSystemNames(path, searchPattern, searchOption, includeFiles: true, includeDirs: false);
1110  }
1111 
1127  {
1128  if (path == null)
1129  {
1130  throw new ArgumentNullException("path");
1131  }
1132  return InternalEnumerateFileSystemEntries(path, "*", SearchOption.TopDirectoryOnly);
1133  }
1134 
1152  public static IEnumerable<string> EnumerateFileSystemEntries(string path, string searchPattern)
1153  {
1154  if (path == null)
1155  {
1156  throw new ArgumentNullException("path");
1157  }
1158  if (searchPattern == null)
1159  {
1160  throw new ArgumentNullException("searchPattern");
1161  }
1162  return InternalEnumerateFileSystemEntries(path, searchPattern, SearchOption.TopDirectoryOnly);
1163  }
1164 
1185  public static IEnumerable<string> EnumerateFileSystemEntries(string path, string searchPattern, SearchOption searchOption)
1186  {
1187  if (path == null)
1188  {
1189  throw new ArgumentNullException("path");
1190  }
1191  if (searchPattern == null)
1192  {
1193  throw new ArgumentNullException("searchPattern");
1194  }
1195  if (searchOption != 0 && searchOption != SearchOption.AllDirectories)
1196  {
1197  throw new ArgumentOutOfRangeException("searchOption", Environment.GetResourceString("ArgumentOutOfRange_Enum"));
1198  }
1199  return InternalEnumerateFileSystemEntries(path, searchPattern, searchOption);
1200  }
1201 
1202  private static IEnumerable<string> InternalEnumerateFileSystemEntries(string path, string searchPattern, SearchOption searchOption)
1203  {
1204  return EnumerateFileSystemNames(path, searchPattern, searchOption, includeFiles: true, includeDirs: true);
1205  }
1206 
1207  private static IEnumerable<string> EnumerateFileSystemNames(string path, string searchPattern, SearchOption searchOption, bool includeFiles, bool includeDirs)
1208  {
1209  return FileSystemEnumerableFactory.CreateFileNameIterator(path, path, searchPattern, includeFiles, includeDirs, searchOption, checkHost: true);
1210  }
1211 
1216  [SecuritySafeCritical]
1217  public static string[] GetLogicalDrives()
1218  {
1219  new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
1220  int logicalDrives = Win32Native.GetLogicalDrives();
1221  if (logicalDrives == 0)
1222  {
1223  __Error.WinIOError();
1224  }
1225  uint num = (uint)logicalDrives;
1226  int num2 = 0;
1227  while (num != 0)
1228  {
1229  if ((num & 1) != 0)
1230  {
1231  num2++;
1232  }
1233  num >>= 1;
1234  }
1235  string[] array = new string[num2];
1236  char[] array2 = new char[3]
1237  {
1238  'A',
1239  ':',
1240  '\\'
1241  };
1242  num = (uint)logicalDrives;
1243  num2 = 0;
1244  while (num != 0)
1245  {
1246  if ((num & 1) != 0)
1247  {
1248  array[num2++] = new string(array2);
1249  }
1250  num >>= 1;
1251  array2[0] += '\u0001';
1252  }
1253  return array;
1254  }
1255 
1265  [SecuritySafeCritical]
1266  public static string GetDirectoryRoot(string path)
1267  {
1268  if (path == null)
1269  {
1270  throw new ArgumentNullException("path");
1271  }
1272  string fullPathInternal = Path.GetFullPathInternal(path);
1273  string text = fullPathInternal.Substring(0, Path.GetRootLength(fullPathInternal));
1274  CheckPermissions(path, text, checkHost: true, FileSecurityStateAccess.PathDiscovery);
1275  return text;
1276  }
1277 
1278  internal static string InternalGetDirectoryRoot(string path)
1279  {
1280  return path?.Substring(0, Path.GetRootLength(path));
1281  }
1282 
1287  [SecuritySafeCritical]
1288  public static string GetCurrentDirectory()
1289  {
1290  return InternalGetCurrentDirectory(checkHost: true);
1291  }
1292 
1293  [SecurityCritical]
1294  internal static string UnsafeGetCurrentDirectory()
1295  {
1296  return InternalGetCurrentDirectory(checkHost: false);
1297  }
1298 
1299  [SecuritySafeCritical]
1300  private static string InternalGetCurrentDirectory(bool checkHost)
1301  {
1302  string text = AppContextSwitches.UseLegacyPathHandling ? LegacyGetCurrentDirectory() : NewGetCurrentDirectory();
1303  CheckPermissions(string.Empty, text, checkHost: true, FileSecurityStateAccess.PathDiscovery);
1304  return text;
1305  }
1306 
1307  [SecurityCritical]
1308  private static string LegacyGetCurrentDirectory()
1309  {
1310  StringBuilder stringBuilder = StringBuilderCache.Acquire(261);
1311  if (Win32Native.GetCurrentDirectory(stringBuilder.Capacity, stringBuilder) == 0)
1312  {
1313  __Error.WinIOError();
1314  }
1315  string text = stringBuilder.ToString();
1316  if (text.IndexOf('~') >= 0)
1317  {
1318  int longPathName = Win32Native.GetLongPathName(text, stringBuilder, stringBuilder.Capacity);
1319  if (longPathName == 0 || longPathName >= 260)
1320  {
1321  int num = Marshal.GetLastWin32Error();
1322  if (longPathName >= 260)
1323  {
1324  num = 206;
1325  }
1326  if (num != 2 && num != 3 && num != 1 && num != 5)
1327  {
1328  __Error.WinIOError(num, string.Empty);
1329  }
1330  }
1331  text = stringBuilder.ToString();
1332  }
1333  StringBuilderCache.Release(stringBuilder);
1334  return text;
1335  }
1336 
1337  [SecurityCritical]
1338  private static string NewGetCurrentDirectory()
1339  {
1340  using (StringBuffer stringBuffer = new StringBuffer(260u))
1341  {
1342  uint num = 0u;
1343  while ((num = Win32Native.GetCurrentDirectoryW(stringBuffer.CharCapacity, stringBuffer.GetHandle())) > stringBuffer.CharCapacity)
1344  {
1345  stringBuffer.EnsureCharCapacity(num);
1346  }
1347  if (num == 0)
1348  {
1349  __Error.WinIOError();
1350  }
1351  stringBuffer.Length = num;
1352  if (stringBuffer.Contains('~'))
1353  {
1354  return LongPathHelper.GetLongPathName(stringBuffer);
1355  }
1356  return stringBuffer.ToString();
1357  }
1358  }
1359 
1371  [SecuritySafeCritical]
1372  public static void SetCurrentDirectory(string path)
1373  {
1374  if (path == null)
1375  {
1376  throw new ArgumentNullException("value");
1377  }
1378  if (path.Length == 0)
1379  {
1380  throw new ArgumentException(Environment.GetResourceString("Argument_PathEmpty"));
1381  }
1382  if (PathInternal.IsPathTooLong(path))
1383  {
1384  throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong"));
1385  }
1386  new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
1387  string fullPathInternal = Path.GetFullPathInternal(path);
1388  if (!Win32Native.SetCurrentDirectory(fullPathInternal))
1389  {
1390  int num = Marshal.GetLastWin32Error();
1391  if (num == 2)
1392  {
1393  num = 3;
1394  }
1395  __Error.WinIOError(num, fullPathInternal);
1396  }
1397  }
1398 
1411  [SecuritySafeCritical]
1412  public static void Move(string sourceDirName, string destDirName)
1413  {
1414  InternalMove(sourceDirName, destDirName, checkHost: true);
1415  }
1416 
1417  [SecurityCritical]
1418  internal static void UnsafeMove(string sourceDirName, string destDirName)
1419  {
1420  InternalMove(sourceDirName, destDirName, checkHost: false);
1421  }
1422 
1423  [SecurityCritical]
1424  private static void InternalMove(string sourceDirName, string destDirName, bool checkHost)
1425  {
1426  if (sourceDirName == null)
1427  {
1428  throw new ArgumentNullException("sourceDirName");
1429  }
1430  if (sourceDirName.Length == 0)
1431  {
1432  throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "sourceDirName");
1433  }
1434  if (destDirName == null)
1435  {
1436  throw new ArgumentNullException("destDirName");
1437  }
1438  if (destDirName.Length == 0)
1439  {
1440  throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "destDirName");
1441  }
1442  string fullPathInternal = Path.GetFullPathInternal(sourceDirName);
1443  string demandDir = GetDemandDir(fullPathInternal, thisDirOnly: false);
1444  if (PathInternal.IsDirectoryTooLong(demandDir))
1445  {
1446  throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong"));
1447  }
1448  string fullPathInternal2 = Path.GetFullPathInternal(destDirName);
1449  string demandDir2 = GetDemandDir(fullPathInternal2, thisDirOnly: false);
1450  if (PathInternal.IsDirectoryTooLong(demandDir))
1451  {
1452  throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong"));
1453  }
1454  FileIOPermission.QuickDemand(FileIOPermissionAccess.Read | FileIOPermissionAccess.Write, demandDir, checkForDuplicates: false, needFullPath: false);
1455  FileIOPermission.QuickDemand(FileIOPermissionAccess.Write, demandDir2, checkForDuplicates: false, needFullPath: false);
1456  if (string.Compare(demandDir, demandDir2, StringComparison.OrdinalIgnoreCase) == 0)
1457  {
1458  throw new IOException(Environment.GetResourceString("IO.IO_SourceDestMustBeDifferent"));
1459  }
1460  string pathRoot = Path.GetPathRoot(demandDir);
1461  string pathRoot2 = Path.GetPathRoot(demandDir2);
1462  if (string.Compare(pathRoot, pathRoot2, StringComparison.OrdinalIgnoreCase) != 0)
1463  {
1464  throw new IOException(Environment.GetResourceString("IO.IO_SourceDestMustHaveSameRoot"));
1465  }
1466  if (!Win32Native.MoveFile(sourceDirName, destDirName))
1467  {
1468  int num = Marshal.GetLastWin32Error();
1469  if (num == 2)
1470  {
1471  num = 3;
1472  __Error.WinIOError(num, fullPathInternal);
1473  }
1474  if (num == 5)
1475  {
1476  throw new IOException(Environment.GetResourceString("UnauthorizedAccess_IODenied_Path", sourceDirName), Win32Native.MakeHRFromErrorCode(num));
1477  }
1478  __Error.WinIOError(num, string.Empty);
1479  }
1480  }
1481 
1493  [SecuritySafeCritical]
1494  public static void Delete(string path)
1495  {
1496  string fullPathInternal = Path.GetFullPathInternal(path);
1497  Delete(fullPathInternal, path, recursive: false, checkHost: true);
1498  }
1499 
1513  [SecuritySafeCritical]
1514  public static void Delete(string path, bool recursive)
1515  {
1516  string fullPathInternal = Path.GetFullPathInternal(path);
1517  Delete(fullPathInternal, path, recursive, checkHost: true);
1518  }
1519 
1520  [SecurityCritical]
1521  internal static void UnsafeDelete(string path, bool recursive)
1522  {
1523  string fullPathInternal = Path.GetFullPathInternal(path);
1524  Delete(fullPathInternal, path, recursive, checkHost: false);
1525  }
1526 
1527  [SecurityCritical]
1528  internal static void Delete(string fullPath, string userPath, bool recursive, bool checkHost)
1529  {
1530  string demandDir = GetDemandDir(fullPath, !recursive);
1531  FileIOPermission.QuickDemand(FileIOPermissionAccess.Write, demandDir, checkForDuplicates: false, needFullPath: false);
1532  Win32Native.WIN32_FILE_ATTRIBUTE_DATA data = default(Win32Native.WIN32_FILE_ATTRIBUTE_DATA);
1533  int num = File.FillAttributeInfo(fullPath, ref data, tryagain: false, returnErrorOnNotFound: true);
1534  if (num != 0)
1535  {
1536  if (num == 2)
1537  {
1538  num = 3;
1539  }
1540  __Error.WinIOError(num, fullPath);
1541  }
1542  if ((data.fileAttributes & 0x400) != 0)
1543  {
1544  recursive = false;
1545  }
1546  DeleteHelper(fullPath, userPath, recursive, throwOnTopLevelDirectoryNotFound: true);
1547  }
1548 
1549  [SecurityCritical]
1550  private static void DeleteHelper(string fullPath, string userPath, bool recursive, bool throwOnTopLevelDirectoryNotFound)
1551  {
1552  Exception ex = null;
1553  int lastWin32Error;
1554  if (recursive)
1555  {
1556  Win32Native.WIN32_FIND_DATA wIN32_FIND_DATA = new Win32Native.WIN32_FIND_DATA();
1557  using (SafeFindHandle safeFindHandle = Win32Native.FindFirstFile(fullPath + "\\*", wIN32_FIND_DATA))
1558  {
1559  if (safeFindHandle.IsInvalid)
1560  {
1561  lastWin32Error = Marshal.GetLastWin32Error();
1562  __Error.WinIOError(lastWin32Error, fullPath);
1563  }
1564  do
1565  {
1566  if ((wIN32_FIND_DATA.dwFileAttributes & 0x10) != 0)
1567  {
1568  if (!wIN32_FIND_DATA.cFileName.Equals(".") && !wIN32_FIND_DATA.cFileName.Equals(".."))
1569  {
1570  if ((wIN32_FIND_DATA.dwFileAttributes & 0x400) == 0)
1571  {
1572  string fullPath2 = Path.InternalCombine(fullPath, wIN32_FIND_DATA.cFileName);
1573  string userPath2 = Path.InternalCombine(userPath, wIN32_FIND_DATA.cFileName);
1574  try
1575  {
1576  DeleteHelper(fullPath2, userPath2, recursive, throwOnTopLevelDirectoryNotFound: false);
1577  }
1578  catch (Exception ex2)
1579  {
1580  if (ex == null)
1581  {
1582  ex = ex2;
1583  }
1584  }
1585  }
1586  else
1587  {
1588  if (wIN32_FIND_DATA.dwReserved0 == -1610612733)
1589  {
1590  string mountPoint = Path.InternalCombine(fullPath, wIN32_FIND_DATA.cFileName + Path.DirectorySeparatorChar.ToString());
1591  if (!Win32Native.DeleteVolumeMountPoint(mountPoint))
1592  {
1593  lastWin32Error = Marshal.GetLastWin32Error();
1594  if (lastWin32Error != 3)
1595  {
1596  try
1597  {
1598  __Error.WinIOError(lastWin32Error, wIN32_FIND_DATA.cFileName);
1599  }
1600  catch (Exception ex3)
1601  {
1602  if (ex == null)
1603  {
1604  ex = ex3;
1605  }
1606  }
1607  }
1608  }
1609  }
1610  string path = Path.InternalCombine(fullPath, wIN32_FIND_DATA.cFileName);
1611  if (!Win32Native.RemoveDirectory(path))
1612  {
1613  lastWin32Error = Marshal.GetLastWin32Error();
1614  if (lastWin32Error != 3)
1615  {
1616  try
1617  {
1618  __Error.WinIOError(lastWin32Error, wIN32_FIND_DATA.cFileName);
1619  }
1620  catch (Exception ex4)
1621  {
1622  if (ex == null)
1623  {
1624  ex = ex4;
1625  }
1626  }
1627  }
1628  }
1629  }
1630  }
1631  }
1632  else
1633  {
1634  string path2 = Path.InternalCombine(fullPath, wIN32_FIND_DATA.cFileName);
1635  if (!Win32Native.DeleteFile(path2))
1636  {
1637  lastWin32Error = Marshal.GetLastWin32Error();
1638  if (lastWin32Error != 2)
1639  {
1640  try
1641  {
1642  __Error.WinIOError(lastWin32Error, wIN32_FIND_DATA.cFileName);
1643  }
1644  catch (Exception ex5)
1645  {
1646  if (ex == null)
1647  {
1648  ex = ex5;
1649  }
1650  }
1651  }
1652  }
1653  }
1654  }
1655  while (Win32Native.FindNextFile(safeFindHandle, wIN32_FIND_DATA));
1656  lastWin32Error = Marshal.GetLastWin32Error();
1657  }
1658  if (ex != null)
1659  {
1660  throw ex;
1661  }
1662  if (lastWin32Error != 0 && lastWin32Error != 18)
1663  {
1664  __Error.WinIOError(lastWin32Error, userPath);
1665  }
1666  }
1667  if (Win32Native.RemoveDirectory(fullPath))
1668  {
1669  return;
1670  }
1671  lastWin32Error = Marshal.GetLastWin32Error();
1672  if (lastWin32Error == 2)
1673  {
1674  lastWin32Error = 3;
1675  }
1676  switch (lastWin32Error)
1677  {
1678  case 5:
1679  throw new IOException(Environment.GetResourceString("UnauthorizedAccess_IODenied_Path", userPath));
1680  case 3:
1681  if (!throwOnTopLevelDirectoryNotFound)
1682  {
1683  return;
1684  }
1685  break;
1686  }
1687  __Error.WinIOError(lastWin32Error, fullPath);
1688  }
1689 
1690  [SecurityCritical]
1691  private static SafeFileHandle OpenHandle(string path)
1692  {
1693  string fullPathInternal = Path.GetFullPathInternal(path);
1694  string pathRoot = Path.GetPathRoot(fullPathInternal);
1695  if (pathRoot == fullPathInternal && pathRoot[1] == Path.VolumeSeparatorChar)
1696  {
1697  throw new ArgumentException(Environment.GetResourceString("Arg_PathIsVolume"));
1698  }
1699  FileIOPermission.QuickDemand(FileIOPermissionAccess.Write, GetDemandDir(fullPathInternal, thisDirOnly: true), checkForDuplicates: false, needFullPath: false);
1700  SafeFileHandle safeFileHandle = Win32Native.SafeCreateFile(fullPathInternal, 1073741824, FileShare.Write | FileShare.Delete, null, FileMode.Open, 33554432, IntPtr.Zero);
1701  if (safeFileHandle.IsInvalid)
1702  {
1703  int lastWin32Error = Marshal.GetLastWin32Error();
1704  __Error.WinIOError(lastWin32Error, fullPathInternal);
1705  }
1706  return safeFileHandle;
1707  }
1708  }
1709 }
static DateTime GetLastAccessTimeUtc(string path)
Returns the date and time, in Coordinated Universal Time (UTC) format, that the specified file or dir...
Definition: Directory.cs:588
Exposes instance methods for creating, moving, and enumerating through directories and subdirectories...
static void SetAccessControl(string path, DirectorySecurity directorySecurity)
Applies access control list (ACL) entries described by a T:System.Security.AccessControl....
Definition: Directory.cs:629
static DateTime GetCreationTime(string path)
Returns the creation date and time of the specified file or directory.
Definition: File.cs:638
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
FileIOPermissionAccess
Specifies the type of file access requested.
static DirectoryInfo GetParent(string path)
Retrieves the parent directory of the specified path, including both absolute and relative paths.
Definition: Directory.cs:55
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
static string [] GetFileSystemEntries(string path, string searchPattern)
Returns an array of file names and directory names that that match a search pattern in a specified pa...
Definition: Directory.cs:860
static string [] GetFileSystemEntries(string path, string searchPattern, SearchOption searchOption)
Returns an array of all the file names and directory names that match a search pattern in a specified...
Definition: Directory.cs:893
long ToFileTimeUtc()
Converts the value of the current T:System.DateTime object to a Windows file time.
Definition: DateTime.cs:1446
static DirectorySecurity GetAccessControl(string path)
Gets a T:System.Security.AccessControl.DirectorySecurity object that encapsulates the access control ...
Definition: Directory.cs:601
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
FileMode
Specifies how the operating system should open a file.
Definition: FileMode.cs:8
static string [] GetFiles(string path)
Returns the names of files (including their paths) in the specified directory.
Definition: Directory.cs:651
static DirectorySecurity GetAccessControl(string path, AccessControlSections includeSections)
Gets a T:System.Security.AccessControl.DirectorySecurity object that encapsulates the specified type ...
Definition: Directory.cs:615
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
static int SizeOf(object structure)
Returns the unmanaged size of an object in bytes.
Definition: Marshal.cs:159
static void SetLastAccessTime(string path, DateTime lastAccessTime)
Sets the date and time the specified file or directory was last accessed.
Definition: Directory.cs:531
static readonly char AltDirectorySeparatorChar
Provides a platform-specific alternate character used to separate directory levels in a path string t...
Definition: Path.cs:23
static DateTime GetLastWriteTime(string path)
Returns the date and time the specified file or directory was last written to.
Definition: File.cs:832
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
Definition: DateTime.cs:13
static IEnumerable< string > EnumerateFiles(string path, string searchPattern)
Returns an enumerable collection of file names that match a search pattern in a specified path.
Definition: Directory.cs:1057
static IEnumerable< string > EnumerateDirectories(string path)
Returns an enumerable collection of directory names in a specified path.
Definition: Directory.cs:936
static readonly char DirectorySeparatorChar
Provides a platform-specific character used to separate directory levels in a path string that reflec...
Definition: Path.cs:17
static unsafe void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc)
Sets the date and time, in Coordinated Universal Time (UTC) format, that the specified file or direct...
Definition: Directory.cs:550
static string [] GetFileSystemEntries(string path)
Returns the names of all files and subdirectories in a specified path.
Definition: Directory.cs:837
static DateTime GetCreationTimeUtc(string path)
Returns the creation date and time, in coordinated universal time (UTC), of the specified file or dir...
Definition: File.cs:655
static DateTime GetLastAccessTimeUtc(string path)
Returns the date and time, in coordinated universal time (UTC), that the specified file or directory ...
Definition: File.cs:752
SearchOption
Specifies whether to search the current directory, or the current directory and all subdirectories.
Definition: SearchOption.cs:8
Represents the access control and audit security for a directory. This class cannot be inherited.
static string [] GetFiles(string path, string searchPattern)
Returns the names of files (including their paths) that match the specified search pattern in the spe...
Definition: Directory.cs:674
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
static void Delete(string path)
Deletes an empty directory from a specified path.
Definition: Directory.cs:1494
sealed override void Persist(string name, AccessControlSections includeSections)
Saves the specified sections of the security descriptor associated with this T:System....
static DateTime GetLastAccessTime(string path)
Returns the date and time the specified file or directory was last accessed.
Definition: Directory.cs:573
Exposes static methods for creating, moving, and enumerating through directories and subdirectories....
Definition: Directory.cs:14
static string [] GetDirectories(string path, string searchPattern)
Returns the names of subdirectories (including their paths) that match the specified search pattern i...
Definition: Directory.cs:767
static void SetCurrentDirectory(string path)
Sets the application's current working directory to the specified directory.
Definition: Directory.cs:1372
static IEnumerable< string > EnumerateFileSystemEntries(string path)
Returns an enumerable collection of file names and directory names in a specified path.
Definition: Directory.cs:1126
static unsafe void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc)
Sets the date and time, in Coordinated Universal Time (UTC) format, that a directory was last written...
Definition: Directory.cs:477
static string GetDirectoryRoot(string path)
Returns the volume information, root information, or both for the specified path.
Definition: Directory.cs:1266
static unsafe void SetCreationTimeUtc(string path, DateTime creationTimeUtc)
Sets the creation date and time, in Coordinated Universal Time (UTC) format, for the specified file o...
Definition: Directory.cs:404
static DateTime GetCreationTimeUtc(string path)
Gets the creation date and time, in Coordinated Universal Time (UTC) format, of a directory.
Definition: Directory.cs:440
static bool Exists(string path)
Determines whether the given path refers to an existing directory on disk.
Definition: Directory.cs:312
static IEnumerable< string > EnumerateDirectories(string path, string searchPattern)
Returns an enumerable collection of directory names that match a search pattern in a specified path.
Definition: Directory.cs:962
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
Definition: Marshal.cs:15
static string GetCurrentDirectory()
Gets the current working directory of the application.
Definition: Directory.cs:1288
static DateTime GetLastWriteTimeUtc(string path)
Returns the date and time, in Coordinated Universal Time (UTC) format, that the specified file or dir...
Definition: Directory.cs:513
static void Delete(string path, bool recursive)
Deletes the specified directory and, if indicated, any subdirectories and files in the directory.
Definition: Directory.cs:1514
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
static DirectoryInfo CreateDirectory(string path, DirectorySecurity directorySecurity)
Creates all the directories in the specified path, unless the already exist, applying the specified W...
Definition: Directory.cs:160
AccessControlActions
Specifies the actions that are permitted for securable objects.
The exception that is thrown when one of the arguments provided to a method is not valid.
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
static string [] GetLogicalDrives()
Retrieves the names of the logical drives on this computer in the form "<drive letter>:\".
Definition: Directory.cs:1217
int Capacity
Gets or sets the maximum number of characters that can be contained in the memory allocated by the cu...
static DateTime GetLastWriteTime(string path)
Returns the date and time the specified file or directory was last written to.
Definition: Directory.cs:499
static void Move(string sourceDirName, string destDirName)
Moves a file or a directory and its contents to a new location.
Definition: Directory.cs:1412
static string [] GetDirectories(string path, string searchPattern, SearchOption searchOption)
Returns the names of the subdirectories (including their paths) that match the specified search patte...
Definition: Directory.cs:797
static DateTime GetLastWriteTimeUtc(string path)
Returns the date and time, in coordinated universal time (UTC), that the specified file or directory ...
Definition: File.cs:849
static IEnumerable< string > EnumerateFileSystemEntries(string path, string searchPattern, SearchOption searchOption)
Returns an enumerable collection of file names and directory names that match a search pattern in a s...
Definition: Directory.cs:1185
Provides static methods for the creation, copying, deletion, moving, and opening of a single file,...
Definition: File.cs:14
static void SetLastWriteTime(string path, DateTime lastWriteTime)
Sets the date and time a directory was last written to.
Definition: Directory.cs:458
static string GetDirectoryName(string path)
Returns the directory information for the specified path string.
Definition: Path.cs:268
static IEnumerable< string > EnumerateFiles(string path)
Returns an enumerable collection of file names in a specified path.
Definition: Directory.cs:1031
Controls the ability to access files and folders. This class cannot be inherited.
static DirectoryInfo CreateDirectory(string path)
Creates all directories and subdirectories in the specified path unless they already exist.
Definition: Directory.cs:89
static IEnumerable< string > EnumerateFileSystemEntries(string path, string searchPattern)
Returns an enumerable collection of file names and directory names that match a search pattern in a s...
Definition: Directory.cs:1152
static int GetLastWin32Error()
Returns the error code returned by the last unmanaged function that was called using platform invoke ...
DateTime ToUniversalTime()
Converts the value of the current T:System.DateTime object to Coordinated Universal Time (UTC).
Definition: DateTime.cs:1569
static void SetCreationTime(string path, DateTime creationTime)
Sets the creation date and time for the specified file or directory.
Definition: Directory.cs:385
SecurityPermissionFlag
Specifies access flags for the security permission object.
AccessControlSections
Specifies which sections of a security descriptor to save or load.
static string [] GetFiles(string path, string searchPattern, SearchOption searchOption)
Returns the names of files (including their paths) that match the specified search pattern in the spe...
Definition: Directory.cs:704
The exception that is thrown when a path or fully qualified file name is longer than the system-defin...
The P:System.Uri.LocalPath data.
The exception that is thrown when a security error is detected.
Performs operations on T:System.String instances that contain file or directory path information....
Definition: Path.cs:13
static DateTime GetLastAccessTime(string path)
Returns the date and time the specified file or directory was last accessed.
Definition: File.cs:735
static IEnumerable< string > EnumerateDirectories(string path, string searchPattern, SearchOption searchOption)
Returns an enumerable collection of directory names that match a search pattern in a specified path,...
Definition: Directory.cs:995
static IEnumerable< string > EnumerateFiles(string path, string searchPattern, SearchOption searchOption)
Returns an enumerable collection of file names that match a search pattern in a specified path,...
Definition: Directory.cs:1090
FileShare
Contains constants for controlling the kind of access other T:System.IO.FileStream objects can have t...
Definition: FileShare.cs:9
static DateTime GetCreationTime(string path)
Gets the creation date and time of a directory.
Definition: Directory.cs:426
static string [] GetDirectories(string path)
Returns the names of subdirectories (including their paths) in the specified directory.
Definition: Directory.cs:744