2 using Microsoft.Win32.SafeHandles;
16 internal sealed
class SearchData
18 public readonly
string fullPath;
20 public readonly
string userPath;
24 public SearchData(
string fullPath,
string userPath,
SearchOption searchOption)
26 this.fullPath = fullPath;
27 this.userPath = userPath;
28 this.searchOption = searchOption;
32 private const int FILE_ATTRIBUTE_DIRECTORY = 16;
34 private const int GENERIC_WRITE = 1073741824;
36 private const int FILE_SHARE_WRITE = 2;
38 private const int FILE_SHARE_DELETE = 4;
40 private const int OPEN_EXISTING = 3;
42 private const int FILE_FLAG_BACKUP_SEMANTICS = 33554432;
65 string fullPathInternal =
Path.GetFullPathInternal(path);
67 if (directoryName ==
null)
88 [SecuritySafeCritical]
99 return InternalCreateDirectoryHelper(path, checkHost:
true);
103 internal static DirectoryInfo UnsafeCreateDirectory(
string path)
109 if (path.Length == 0)
113 return InternalCreateDirectoryHelper(path, checkHost:
false);
117 internal static DirectoryInfo InternalCreateDirectoryHelper(
string path,
bool checkHost)
119 string fullPathAndCheckPermissions = GetFullPathAndCheckPermissions(path, checkHost);
120 InternalCreateDirectory(fullPathAndCheckPermissions, path,
null, checkHost);
121 return new DirectoryInfo(fullPathAndCheckPermissions, junk:
false);
124 internal static string GetFullPathAndCheckPermissions(
string path,
bool checkHost, FileSecurityStateAccess access = FileSecurityStateAccess.Read)
126 string fullPathInternal =
Path.GetFullPathInternal(path);
127 CheckPermissions(path, fullPathInternal, checkHost, access);
128 return fullPathInternal;
131 [SecuritySafeCritical]
132 internal static void CheckPermissions(
string displayPath,
string fullPath,
bool checkHost, FileSecurityStateAccess access = FileSecurityStateAccess.Read)
134 if (CodeAccessSecurityEngine.QuickCheckForAllDemands())
159 [SecuritySafeCritical]
166 if (path.Length == 0)
170 string fullPathAndCheckPermissions = GetFullPathAndCheckPermissions(path, checkHost:
true);
171 InternalCreateDirectory(fullPathAndCheckPermissions, path, directorySecurity);
172 return new DirectoryInfo(fullPathAndCheckPermissions, junk:
false);
175 internal static string GetDemandDir(
string fullPath,
bool thisDirOnly)
181 return fullPath +
".";
183 return fullPath +
"\\.";
185 if (!fullPath.EndsWith(Path.DirectorySeparatorChar) && !fullPath.EndsWith(Path.AltDirectorySeparatorChar))
187 return fullPath +
"\\";
192 internal static void InternalCreateDirectory(
string fullPath,
string path,
object dirSecurityObj)
194 InternalCreateDirectory(fullPath, path, dirSecurityObj, checkHost:
false);
197 [SecuritySafeCritical]
198 internal unsafe
static void InternalCreateDirectory(
string fullPath,
string path,
object dirSecurityObj,
bool checkHost)
201 int num = fullPath.Length;
202 if (num >= 2 &&
Path.IsDirectorySeparator(fullPath[num - 1]))
206 int rootLength =
Path.GetRootLength(fullPath);
207 if (num == 2 &&
Path.IsDirectorySeparator(fullPath[1]))
209 throw new IOException(Environment.GetResourceString(
"IO.IO_CannotCreateDirectory", path));
211 if (InternalExists(fullPath))
217 if (num > rootLength)
220 while (num2 >= rootLength && !flag)
222 string text = fullPath.Substring(0, num2 + 1);
223 if (!InternalExists(text))
231 while (num2 > rootLength && fullPath[num2] !=
Path.DirectorySeparatorChar && fullPath[num2] !=
Path.AltDirectorySeparatorChar)
238 int count = list.Count;
239 if (list.Count != 0 && !CodeAccessSecurityEngine.QuickCheckForAllDemands())
241 string[] array =
new string[list.Count];
242 list.CopyTo(array, 0);
243 for (
int i = 0; i < array.Length; i++)
250 Win32Native.SECURITY_ATTRIBUTES sECURITY_ATTRIBUTES =
null;
251 if (directorySecurity !=
null)
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;
262 string maybeFullPath = path;
263 while (list.Count > 0)
265 string text2 = list[list.Count - 1];
266 list.RemoveAt(list.Count - 1);
267 if (PathInternal.IsDirectoryTooLong(text2))
269 throw new PathTooLongException(Environment.GetResourceString(
"IO.PathTooLong"));
271 flag2 = Win32Native.CreateDirectory(text2, sECURITY_ATTRIBUTES);
272 if (!flag2 && num3 == 0)
275 if (lastError != 183)
279 else if (File.InternalExists(text2) || (!InternalExists(text2, out lastError) && lastError == 5))
284 CheckPermissions(
string.Empty, text2, checkHost, FileSecurityStateAccess.PathDiscovery);
285 maybeFullPath = text2;
293 if (count == 0 && !flag)
295 string path2 = InternalGetDirectoryRoot(fullPath);
296 if (!InternalExists(path2))
298 __Error.WinIOError(3, InternalGetDirectoryRoot(path));
301 else if (!flag2 && num3 != 0)
303 __Error.WinIOError(num3, maybeFullPath);
311 [SecuritySafeCritical]
314 return InternalExistsHelper(path, checkHost:
true);
318 internal static bool UnsafeExists(
string path)
320 return InternalExistsHelper(path, checkHost:
false);
324 internal static bool InternalExistsHelper(
string path,
bool checkHost)
326 if (path ==
null || path.Length == 0)
332 string fullPathAndCheckPermissions = GetFullPathAndCheckPermissions(path, checkHost);
333 return InternalExists(fullPathAndCheckPermissions);
335 catch (ArgumentException)
338 catch (NotSupportedException)
347 catch (UnauthorizedAccessException)
354 internal static bool InternalExists(
string path)
357 return InternalExists(path, out lastError);
361 internal static bool InternalExists(
string path, out
int lastError)
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)
367 return (data.fileAttributes & 0x10) != 0;
403 [SecuritySafeCritical]
406 using (SafeFileHandle hFile = OpenHandle(path))
408 Win32Native.FILE_TIME fILE_TIME =
new Win32Native.FILE_TIME(creationTimeUtc.
ToFileTimeUtc());
409 if (!Win32Native.SetFileTime(hFile, &fILE_TIME,
null,
null))
412 __Error.WinIOError(lastWin32Error, path);
476 [SecuritySafeCritical]
479 using (SafeFileHandle hFile = OpenHandle(path))
481 Win32Native.FILE_TIME fILE_TIME =
new Win32Native.FILE_TIME(lastWriteTimeUtc.
ToFileTimeUtc());
482 if (!Win32Native.SetFileTime(hFile,
null,
null, &fILE_TIME))
485 __Error.WinIOError(lastWin32Error, path);
549 [SecuritySafeCritical]
552 using (SafeFileHandle hFile = OpenHandle(path))
554 Win32Native.FILE_TIME fILE_TIME =
new Win32Native.FILE_TIME(lastAccessTimeUtc.
ToFileTimeUtc());
555 if (!Win32Native.SetFileTime(hFile,
null, &fILE_TIME,
null))
558 __Error.WinIOError(lastWin32Error, path);
628 [SecuritySafeCritical]
631 if (directorySecurity ==
null)
635 string fullPathInternal =
Path.GetFullPathInternal(path);
636 directorySecurity.
Persist(fullPathInternal);
657 return InternalGetFiles(path,
"*",
SearchOption.TopDirectoryOnly);
674 public static string[]
GetFiles(
string path,
string searchPattern)
680 if (searchPattern ==
null)
684 return InternalGetFiles(path, searchPattern,
SearchOption.TopDirectoryOnly);
710 if (searchPattern ==
null)
714 if (searchOption != 0 && searchOption !=
SearchOption.AllDirectories)
718 return InternalGetFiles(path, searchPattern, searchOption);
721 private static string[] InternalGetFiles(
string path,
string searchPattern,
SearchOption searchOption)
723 return InternalGetFileDirectoryNames(path, path, searchPattern, includeFiles:
true, includeDirs:
false, searchOption, checkHost:
true);
727 internal static string[] UnsafeGetFiles(
string path,
string searchPattern,
SearchOption searchOption)
729 return InternalGetFileDirectoryNames(path, path, searchPattern, includeFiles:
true, includeDirs:
false, searchOption, checkHost:
false);
750 return InternalGetDirectories(path,
"*",
SearchOption.TopDirectoryOnly);
773 if (searchPattern ==
null)
777 return InternalGetDirectories(path, searchPattern,
SearchOption.TopDirectoryOnly);
803 if (searchPattern ==
null)
807 if (searchOption != 0 && searchOption !=
SearchOption.AllDirectories)
811 return InternalGetDirectories(path, searchPattern, searchOption);
814 private static string[] InternalGetDirectories(
string path,
string searchPattern,
SearchOption searchOption)
816 return InternalGetFileDirectoryNames(path, path, searchPattern, includeFiles:
false, includeDirs:
true, searchOption, checkHost:
true);
820 internal static string[] UnsafeGetDirectories(
string path,
string searchPattern,
SearchOption searchOption)
822 return InternalGetFileDirectoryNames(path, path, searchPattern, includeFiles:
false, includeDirs:
true, searchOption, checkHost:
false);
843 return InternalGetFileSystemEntries(path,
"*",
SearchOption.TopDirectoryOnly);
866 if (searchPattern ==
null)
870 return InternalGetFileSystemEntries(path, searchPattern,
SearchOption.TopDirectoryOnly);
899 if (searchPattern ==
null)
903 if (searchOption != 0 && searchOption !=
SearchOption.AllDirectories)
907 return InternalGetFileSystemEntries(path, searchPattern, searchOption);
910 private static string[] InternalGetFileSystemEntries(
string path,
string searchPattern,
SearchOption searchOption)
912 return InternalGetFileDirectoryNames(path, path, searchPattern, includeFiles:
true, includeDirs:
true, searchOption, checkHost:
true);
915 internal static string[] InternalGetFileDirectoryNames(
string path,
string userPathOriginal,
string searchPattern,
bool includeFiles,
bool includeDirs,
SearchOption searchOption,
bool checkHost)
917 IEnumerable<string> collection = FileSystemEnumerableFactory.CreateFileNameIterator(path, userPathOriginal, searchPattern, includeFiles, includeDirs, searchOption, checkHost);
919 return list.ToArray();
942 return InternalEnumerateDirectories(path,
"*",
SearchOption.TopDirectoryOnly);
968 if (searchPattern ==
null)
972 return InternalEnumerateDirectories(path, searchPattern,
SearchOption.TopDirectoryOnly);
1001 if (searchPattern ==
null)
1005 if (searchOption != 0 && searchOption !=
SearchOption.AllDirectories)
1009 return InternalEnumerateDirectories(path, searchPattern, searchOption);
1014 return EnumerateFileSystemNames(path, searchPattern, searchOption, includeFiles:
false, includeDirs:
true);
1037 return InternalEnumerateFiles(path,
"*",
SearchOption.TopDirectoryOnly);
1063 if (searchPattern ==
null)
1067 return InternalEnumerateFiles(path, searchPattern,
SearchOption.TopDirectoryOnly);
1096 if (searchPattern ==
null)
1100 if (searchOption != 0 && searchOption !=
SearchOption.AllDirectories)
1104 return InternalEnumerateFiles(path, searchPattern, searchOption);
1109 return EnumerateFileSystemNames(path, searchPattern, searchOption, includeFiles:
true, includeDirs:
false);
1132 return InternalEnumerateFileSystemEntries(path,
"*",
SearchOption.TopDirectoryOnly);
1158 if (searchPattern ==
null)
1162 return InternalEnumerateFileSystemEntries(path, searchPattern,
SearchOption.TopDirectoryOnly);
1191 if (searchPattern ==
null)
1195 if (searchOption != 0 && searchOption !=
SearchOption.AllDirectories)
1199 return InternalEnumerateFileSystemEntries(path, searchPattern, searchOption);
1204 return EnumerateFileSystemNames(path, searchPattern, searchOption, includeFiles:
true, includeDirs:
true);
1207 private static IEnumerable<string> EnumerateFileSystemNames(
string path,
string searchPattern,
SearchOption searchOption,
bool includeFiles,
bool includeDirs)
1209 return FileSystemEnumerableFactory.CreateFileNameIterator(path, path, searchPattern, includeFiles, includeDirs, searchOption, checkHost:
true);
1216 [SecuritySafeCritical]
1220 int logicalDrives = Win32Native.GetLogicalDrives();
1221 if (logicalDrives == 0)
1223 __Error.WinIOError();
1225 uint num = (uint)logicalDrives;
1235 string[] array =
new string[num2];
1236 char[] array2 =
new char[3]
1242 num = (uint)logicalDrives;
1248 array[num2++] =
new string(array2);
1251 array2[0] +=
'\u0001';
1265 [SecuritySafeCritical]
1272 string fullPathInternal =
Path.GetFullPathInternal(path);
1273 string text = fullPathInternal.Substring(0,
Path.GetRootLength(fullPathInternal));
1274 CheckPermissions(path, text, checkHost:
true, FileSecurityStateAccess.PathDiscovery);
1278 internal static string InternalGetDirectoryRoot(
string path)
1280 return path?.Substring(0,
Path.GetRootLength(path));
1287 [SecuritySafeCritical]
1290 return InternalGetCurrentDirectory(checkHost:
true);
1294 internal static string UnsafeGetCurrentDirectory()
1296 return InternalGetCurrentDirectory(checkHost:
false);
1299 [SecuritySafeCritical]
1300 private static string InternalGetCurrentDirectory(
bool checkHost)
1302 string text = AppContextSwitches.UseLegacyPathHandling ? LegacyGetCurrentDirectory() : NewGetCurrentDirectory();
1303 CheckPermissions(
string.Empty, text, checkHost:
true, FileSecurityStateAccess.PathDiscovery);
1308 private static string LegacyGetCurrentDirectory()
1310 StringBuilder stringBuilder = StringBuilderCache.Acquire(261);
1311 if (Win32Native.GetCurrentDirectory(stringBuilder.
Capacity, stringBuilder) == 0)
1313 __Error.WinIOError();
1315 string text = stringBuilder.
ToString();
1316 if (text.IndexOf(
'~') >= 0)
1318 int longPathName = Win32Native.GetLongPathName(text, stringBuilder, stringBuilder.
Capacity);
1319 if (longPathName == 0 || longPathName >= 260)
1322 if (longPathName >= 260)
1326 if (num != 2 && num != 3 && num != 1 && num != 5)
1328 __Error.WinIOError(num,
string.Empty);
1333 StringBuilderCache.Release(stringBuilder);
1338 private static string NewGetCurrentDirectory()
1340 using (StringBuffer stringBuffer =
new StringBuffer(260u))
1343 while ((num = Win32Native.GetCurrentDirectoryW(stringBuffer.CharCapacity, stringBuffer.GetHandle())) > stringBuffer.CharCapacity)
1345 stringBuffer.EnsureCharCapacity(num);
1349 __Error.WinIOError();
1351 stringBuffer.Length = num;
1352 if (stringBuffer.Contains(
'~'))
1354 return LongPathHelper.GetLongPathName(stringBuffer);
1356 return stringBuffer.ToString();
1371 [SecuritySafeCritical]
1378 if (path.Length == 0)
1382 if (PathInternal.IsPathTooLong(path))
1387 string fullPathInternal =
Path.GetFullPathInternal(path);
1388 if (!Win32Native.SetCurrentDirectory(fullPathInternal))
1395 __Error.WinIOError(num, fullPathInternal);
1411 [SecuritySafeCritical]
1412 public static void Move(
string sourceDirName,
string destDirName)
1414 InternalMove(sourceDirName, destDirName, checkHost:
true);
1418 internal static void UnsafeMove(
string sourceDirName,
string destDirName)
1420 InternalMove(sourceDirName, destDirName, checkHost:
false);
1424 private static void InternalMove(
string sourceDirName,
string destDirName,
bool checkHost)
1426 if (sourceDirName ==
null)
1430 if (sourceDirName.Length == 0)
1432 throw new ArgumentException(Environment.GetResourceString(
"Argument_EmptyFileName"),
"sourceDirName");
1434 if (destDirName ==
null)
1436 throw new ArgumentNullException(
"destDirName");
1438 if (destDirName.Length == 0)
1440 throw new ArgumentException(Environment.GetResourceString(
"Argument_EmptyFileName"),
"destDirName");
1442 string fullPathInternal =
Path.GetFullPathInternal(sourceDirName);
1443 string demandDir = GetDemandDir(fullPathInternal, thisDirOnly:
false);
1444 if (PathInternal.IsDirectoryTooLong(demandDir))
1446 throw new PathTooLongException(Environment.GetResourceString(
"IO.PathTooLong"));
1448 string fullPathInternal2 =
Path.GetFullPathInternal(destDirName);
1449 string demandDir2 = GetDemandDir(fullPathInternal2, thisDirOnly:
false);
1450 if (PathInternal.IsDirectoryTooLong(demandDir))
1452 throw new PathTooLongException(Environment.GetResourceString(
"IO.PathTooLong"));
1456 if (
string.Compare(demandDir, demandDir2,
StringComparison.OrdinalIgnoreCase) == 0)
1458 throw new IOException(Environment.GetResourceString(
"IO.IO_SourceDestMustBeDifferent"));
1460 string pathRoot =
Path.GetPathRoot(demandDir);
1461 string pathRoot2 =
Path.GetPathRoot(demandDir2);
1462 if (
string.Compare(pathRoot, pathRoot2,
StringComparison.OrdinalIgnoreCase) != 0)
1464 throw new IOException(Environment.GetResourceString(
"IO.IO_SourceDestMustHaveSameRoot"));
1466 if (!Win32Native.MoveFile(sourceDirName, destDirName))
1472 __Error.WinIOError(num, fullPathInternal);
1476 throw new IOException(Environment.GetResourceString(
"UnauthorizedAccess_IODenied_Path", sourceDirName), Win32Native.MakeHRFromErrorCode(num));
1478 __Error.WinIOError(num,
string.Empty);
1493 [SecuritySafeCritical]
1496 string fullPathInternal =
Path.GetFullPathInternal(path);
1497 Delete(fullPathInternal, path, recursive:
false, checkHost:
true);
1513 [SecuritySafeCritical]
1514 public static void Delete(
string path,
bool recursive)
1516 string fullPathInternal =
Path.GetFullPathInternal(path);
1517 Delete(fullPathInternal, path, recursive, checkHost:
true);
1521 internal static void UnsafeDelete(
string path,
bool recursive)
1523 string fullPathInternal =
Path.GetFullPathInternal(path);
1524 Delete(fullPathInternal, path, recursive, checkHost:
false);
1528 internal static void Delete(
string fullPath,
string userPath,
bool recursive,
bool checkHost)
1530 string demandDir = GetDemandDir(fullPath, !recursive);
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);
1540 __Error.WinIOError(num, fullPath);
1542 if ((data.fileAttributes & 0x400) != 0)
1546 DeleteHelper(fullPath, userPath, recursive, throwOnTopLevelDirectoryNotFound:
true);
1550 private static void DeleteHelper(
string fullPath,
string userPath,
bool recursive,
bool throwOnTopLevelDirectoryNotFound)
1552 Exception ex =
null;
1556 Win32Native.WIN32_FIND_DATA wIN32_FIND_DATA =
new Win32Native.WIN32_FIND_DATA();
1557 using (SafeFindHandle safeFindHandle = Win32Native.FindFirstFile(fullPath +
"\\*", wIN32_FIND_DATA))
1559 if (safeFindHandle.IsInvalid)
1562 __Error.WinIOError(lastWin32Error, fullPath);
1566 if ((wIN32_FIND_DATA.dwFileAttributes & 0x10) != 0)
1568 if (!wIN32_FIND_DATA.cFileName.Equals(
".") && !wIN32_FIND_DATA.cFileName.Equals(
".."))
1570 if ((wIN32_FIND_DATA.dwFileAttributes & 0x400) == 0)
1572 string fullPath2 =
Path.InternalCombine(fullPath, wIN32_FIND_DATA.cFileName);
1573 string userPath2 =
Path.InternalCombine(userPath, wIN32_FIND_DATA.cFileName);
1576 DeleteHelper(fullPath2, userPath2, recursive, throwOnTopLevelDirectoryNotFound:
false);
1578 catch (Exception ex2)
1588 if (wIN32_FIND_DATA.dwReserved0 == -1610612733)
1590 string mountPoint =
Path.InternalCombine(fullPath, wIN32_FIND_DATA.cFileName +
Path.DirectorySeparatorChar.ToString());
1591 if (!Win32Native.DeleteVolumeMountPoint(mountPoint))
1594 if (lastWin32Error != 3)
1598 __Error.WinIOError(lastWin32Error, wIN32_FIND_DATA.cFileName);
1600 catch (Exception ex3)
1610 string path =
Path.InternalCombine(fullPath, wIN32_FIND_DATA.cFileName);
1611 if (!Win32Native.RemoveDirectory(path))
1614 if (lastWin32Error != 3)
1618 __Error.WinIOError(lastWin32Error, wIN32_FIND_DATA.cFileName);
1620 catch (Exception ex4)
1634 string path2 =
Path.InternalCombine(fullPath, wIN32_FIND_DATA.cFileName);
1635 if (!Win32Native.DeleteFile(path2))
1638 if (lastWin32Error != 2)
1642 __Error.WinIOError(lastWin32Error, wIN32_FIND_DATA.cFileName);
1644 catch (Exception ex5)
1655 while (Win32Native.FindNextFile(safeFindHandle, wIN32_FIND_DATA));
1662 if (lastWin32Error != 0 && lastWin32Error != 18)
1664 __Error.WinIOError(lastWin32Error, userPath);
1667 if (Win32Native.RemoveDirectory(fullPath))
1672 if (lastWin32Error == 2)
1676 switch (lastWin32Error)
1679 throw new IOException(Environment.GetResourceString(
"UnauthorizedAccess_IODenied_Path", userPath));
1681 if (!throwOnTopLevelDirectoryNotFound)
1687 __Error.WinIOError(lastWin32Error, fullPath);
1691 private static SafeFileHandle OpenHandle(
string path)
1693 string fullPathInternal =
Path.GetFullPathInternal(path);
1694 string pathRoot =
Path.GetPathRoot(fullPathInternal);
1695 if (pathRoot == fullPathInternal && pathRoot[1] ==
Path.VolumeSeparatorChar)
1697 throw new ArgumentException(Environment.GetResourceString(
"Arg_PathIsVolume"));
1700 SafeFileHandle safeFileHandle = Win32Native.SafeCreateFile(fullPathInternal, 1073741824,
FileShare.Write |
FileShare.Delete,
null,
FileMode.Open, 33554432, IntPtr.Zero);
1701 if (safeFileHandle.IsInvalid)
1704 __Error.WinIOError(lastWin32Error, fullPathInternal);
1706 return safeFileHandle;
static DateTime GetLastAccessTimeUtc(string path)
Returns the date and time, in Coordinated Universal Time (UTC) format, that the specified file or dir...
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....
static DateTime GetCreationTime(string path)
Returns the creation date and time of the specified file or directory.
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.
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...
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...
long ToFileTimeUtc()
Converts the value of the current T:System.DateTime object to a Windows file time.
static DirectorySecurity GetAccessControl(string path)
Gets a T:System.Security.AccessControl.DirectorySecurity object that encapsulates the access control ...
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.
static string [] GetFiles(string path)
Returns the names of files (including their paths) in the specified directory.
static DirectorySecurity GetAccessControl(string path, AccessControlSections includeSections)
Gets a T:System.Security.AccessControl.DirectorySecurity object that encapsulates the specified type ...
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.
static void SetLastAccessTime(string path, DateTime lastAccessTime)
Sets the date and time the specified file or directory was last accessed.
static readonly char AltDirectorySeparatorChar
Provides a platform-specific alternate character used to separate directory levels in a path string t...
static DateTime GetLastWriteTime(string path)
Returns the date and time the specified file or directory was last written to.
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
static IEnumerable< string > EnumerateFiles(string path, string searchPattern)
Returns an enumerable collection of file names that match a search pattern in a specified path.
static IEnumerable< string > EnumerateDirectories(string path)
Returns an enumerable collection of directory names in a specified path.
static readonly char DirectorySeparatorChar
Provides a platform-specific character used to separate directory levels in a path string that reflec...
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...
static string [] GetFileSystemEntries(string path)
Returns the names of all files and subdirectories in a specified path.
static DateTime GetCreationTimeUtc(string path)
Returns the creation date and time, in coordinated universal time (UTC), of the specified file or dir...
static DateTime GetLastAccessTimeUtc(string path)
Returns the date and time, in coordinated universal time (UTC), that the specified file or directory ...
SearchOption
Specifies whether to search the current directory, or the current directory and all subdirectories.
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...
Provides information about, and means to manipulate, the current environment and platform....
static void Delete(string path)
Deletes an empty directory from a specified path.
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.
Exposes static methods for creating, moving, and enumerating through directories and subdirectories....
static string [] GetDirectories(string path, string searchPattern)
Returns the names of subdirectories (including their paths) that match the specified search pattern i...
static void SetCurrentDirectory(string path)
Sets the application's current working directory to the specified directory.
static IEnumerable< string > EnumerateFileSystemEntries(string path)
Returns an enumerable collection of file names and directory names in a specified path.
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...
static string GetDirectoryRoot(string path)
Returns the volume information, root information, or both for the specified path.
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...
static DateTime GetCreationTimeUtc(string path)
Gets the creation date and time, in Coordinated Universal Time (UTC) format, of a directory.
static bool Exists(string path)
Determines whether the given path refers to an existing directory on disk.
static IEnumerable< string > EnumerateDirectories(string path, string searchPattern)
Returns an enumerable collection of directory names that match a search pattern in a specified path.
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
static string GetCurrentDirectory()
Gets the current working directory of the application.
static DateTime GetLastWriteTimeUtc(string path)
Returns the date and time, in Coordinated Universal Time (UTC) format, that the specified file or dir...
static void Delete(string path, bool recursive)
Deletes the specified directory and, if indicated, any subdirectories and files in the directory.
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...
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>:\".
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.
static void Move(string sourceDirName, string destDirName)
Moves a file or a directory and its contents to a new location.
static string [] GetDirectories(string path, string searchPattern, SearchOption searchOption)
Returns the names of the subdirectories (including their paths) that match the specified search patte...
static DateTime GetLastWriteTimeUtc(string path)
Returns the date and time, in coordinated universal time (UTC), that the specified file or directory ...
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...
Provides static methods for the creation, copying, deletion, moving, and opening of a single file,...
static void SetLastWriteTime(string path, DateTime lastWriteTime)
Sets the date and time a directory was last written to.
static string GetDirectoryName(string path)
Returns the directory information for the specified path string.
static IEnumerable< string > EnumerateFiles(string path)
Returns an enumerable collection of file names in a specified path.
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.
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...
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).
static void SetCreationTime(string path, DateTime creationTime)
Sets the creation date and time for the specified file or directory.
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...
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....
static DateTime GetLastAccessTime(string path)
Returns the date and time the specified file or directory was last accessed.
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,...
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,...
FileShare
Contains constants for controlling the kind of access other T:System.IO.FileStream objects can have t...
static DateTime GetCreationTime(string path)
Gets the creation date and time of a directory.
static string [] GetDirectories(string path)
Returns the names of subdirectories (including their paths) in the specified directory.