[System.Security.SecuritySafeCritical] // auto-generated public static bool Exists(String path) { try { if (path == null) { return(false); } if (path.Length == 0) { return(false); } String fullPath = PathHelpers.GetFullPathInternal(path); return(FileSystem.Current.DirectoryExists(fullPath)); } catch (ArgumentException) { } catch (NotSupportedException) { } // Security can throw this on ":" catch (SecurityException) { } catch (IOException) { } catch (UnauthorizedAccessException) { } return(false); }
public void MoveTo(String destFileName) { if (destFileName == null) { throw new ArgumentNullException("destFileName"); } if (destFileName.Length == 0) { throw new ArgumentException(SR.Argument_EmptyFileName, "destFileName"); } Contract.EndContractBlock(); String fullDestFileName = PathHelpers.GetFullPathInternal(destFileName); // These checks are in place to ensure Unix error throwing happens the same way // as it does on Windows.These checks can be removed if a solution to #2460 is // found that doesn't require validity checks before making an API call. if (!new DirectoryInfo(Path.GetDirectoryName(FullName)).Exists) { throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, FullName)); } if (!Exists) { throw new FileNotFoundException(SR.Format(SR.IO_FileNotFound_FileName, FullName), FullName); } FileSystem.Current.MoveFile(FullPath, fullDestFileName); FullPath = fullDestFileName; OriginalPath = destFileName; _name = Path.GetFileName(fullDestFileName); DisplayPath = GetDisplayPath(destFileName); // Flush any cached information about the file. Invalidate(); }
public static void Move(String sourceFileName, String destFileName) { if (sourceFileName == null) { throw new ArgumentNullException("sourceFileName", SR.ArgumentNull_FileName); } if (destFileName == null) { throw new ArgumentNullException("destFileName", SR.ArgumentNull_FileName); } if (sourceFileName.Length == 0) { throw new ArgumentException(SR.Argument_EmptyFileName, "sourceFileName"); } if (destFileName.Length == 0) { throw new ArgumentException(SR.Argument_EmptyFileName, "destFileName"); } Contract.EndContractBlock(); String fullSourceFileName = PathHelpers.GetFullPathInternal(sourceFileName); String fullDestFileName = PathHelpers.GetFullPathInternal(destFileName); if (!InternalExists(fullSourceFileName)) { throw new FileNotFoundException(SR.Format(SR.IO_FileNotFound_FileName, fullSourceFileName), fullSourceFileName); } FileSystem.Current.MoveFile(fullSourceFileName, fullDestFileName); }
public static bool Exists(String path) { try { if (path == null) { return(false); } if (path.Length == 0) { return(false); } path = PathHelpers.GetFullPathInternal(path); // After normalizing, check whether path ends in directory separator. // Otherwise, FillAttributeInfo removes it and we may return a false positive. // GetFullPath should never return null Debug.Assert(path != null, "File.Exists: GetFullPath returned null"); if (path.Length > 0 && PathHelpers.IsDirectorySeparator(path[path.Length - 1])) { return(false); } return(InternalExists(path)); } catch (ArgumentException) { } catch (NotSupportedException) { } // Security can throw this on ":" catch (SecurityException) { } catch (IOException) { } catch (UnauthorizedAccessException) { } return(false); }
public static void Move(String sourceDirName, String destDirName) { if (sourceDirName == null) { throw new ArgumentNullException("sourceDirName"); } if (sourceDirName.Length == 0) { throw new ArgumentException(SR.Argument_EmptyFileName, "sourceDirName"); } if (destDirName == null) { throw new ArgumentNullException("destDirName"); } if (destDirName.Length == 0) { throw new ArgumentException(SR.Argument_EmptyFileName, "destDirName"); } Contract.EndContractBlock(); String fullsourceDirName = PathHelpers.GetFullPathInternal(sourceDirName); String sourcePath = EnsureTrailingDirectorySeparator(fullsourceDirName); int maxDirectoryPath = FileSystem.Current.MaxDirectoryPath; if (sourcePath.Length >= maxDirectoryPath) { throw new PathTooLongException(SR.IO_PathTooLong); } String fulldestDirName = PathHelpers.GetFullPathInternal(destDirName); String destPath = EnsureTrailingDirectorySeparator(fulldestDirName); if (destPath.Length >= maxDirectoryPath) { throw new PathTooLongException(SR.IO_PathTooLong); } StringComparison pathComparison = PathInternal.GetComparison(); if (String.Compare(sourcePath, destPath, pathComparison) == 0) { throw new IOException(SR.IO_SourceDestMustBeDifferent); } String sourceRoot = Path.GetPathRoot(sourcePath); String destinationRoot = Path.GetPathRoot(destPath); if (String.Compare(sourceRoot, destinationRoot, pathComparison) != 0) { throw new IOException(SR.IO_SourceDestMustHaveSameRoot); } FileSystem.Current.MoveDirectory(fullsourceDirName, fulldestDirName); }
private void Init(String fileName) { OriginalPath = fileName; // Must fully qualify the path for the security check String fullPath = PathHelpers.GetFullPathInternal(fileName); _name = Path.GetFileName(fileName); FullPath = fullPath; DisplayPath = GetDisplayPath(fileName); }
public void MoveTo(String destDirName) { if (destDirName == null) { throw new ArgumentNullException("destDirName"); } if (destDirName.Length == 0) { throw new ArgumentException(SR.Argument_EmptyFileName, "destDirName"); } Contract.EndContractBlock(); String fullDestDirName = PathHelpers.GetFullPathInternal(destDirName); if (fullDestDirName[fullDestDirName.Length - 1] != Path.DirectorySeparatorChar) { fullDestDirName = fullDestDirName + PathHelpers.DirectorySeparatorCharAsString; } String fullSourcePath; if (FullPath.Length > 0 && FullPath[FullPath.Length - 1] == Path.DirectorySeparatorChar) { fullSourcePath = FullPath; } else { fullSourcePath = FullPath + PathHelpers.DirectorySeparatorCharAsString; } StringComparison pathComparison = PathHelpers.GetComparison(FileSystem.Current.CaseSensitive); if (String.Compare(fullSourcePath, fullDestDirName, pathComparison) == 0) { throw new IOException(SR.IO_SourceDestMustBeDifferent); } String sourceRoot = Path.GetPathRoot(fullSourcePath); String destinationRoot = Path.GetPathRoot(fullDestDirName); if (String.Compare(sourceRoot, destinationRoot, pathComparison) != 0) { throw new IOException(SR.IO_SourceDestMustHaveSameRoot); } FileSystem.Current.MoveDirectory(FullPath, fullDestDirName); FullPath = fullDestDirName; OriginalPath = destDirName; DisplayPath = GetDisplayName(OriginalPath, FullPath); // Flush any cached information about the directory. Invalidate(); }
public static void Delete(String path) { if (path == null) { throw new ArgumentNullException("path"); } Contract.EndContractBlock(); String fullPath = PathHelpers.GetFullPathInternal(path); FileSystem.Current.DeleteFile(fullPath); }
public DirectoryInfo(String path) { if (path == null) { throw new ArgumentNullException("path"); } Contract.EndContractBlock(); OriginalPath = PathHelpers.ShouldReviseDirectoryPathToCurrent(path) ? "." : path; FullPath = PathHelpers.GetFullPathInternal(path); DisplayPath = GetDisplayName(OriginalPath, FullPath); }
public static String GetDirectoryRoot(String path) { if (path == null) { throw new ArgumentNullException("path"); } Contract.EndContractBlock(); String fullPath = PathHelpers.GetFullPathInternal(path); String root = fullPath.Substring(0, PathHelpers.GetRootLength(fullPath)); return(root); }
internal static String InternalCopy(String sourceFileName, String destFileName, bool overwrite) { Contract.Requires(sourceFileName != null); Contract.Requires(destFileName != null); Contract.Requires(sourceFileName.Length > 0); Contract.Requires(destFileName.Length > 0); String fullSourceFileName = PathHelpers.GetFullPathInternal(sourceFileName); String fullDestFileName = PathHelpers.GetFullPathInternal(destFileName); FileSystem.Current.CopyFile(fullSourceFileName, fullDestFileName, overwrite); return(fullDestFileName); }
private void Init(String path) { // Special case "<DriveLetter>:" to point to "<CurrentDirectory>" instead if ((path.Length == 2) && (path[1] == ':')) { OriginalPath = "."; } else { OriginalPath = path; } String fullPath = PathHelpers.GetFullPathInternal(path); FullPath = fullPath; DisplayPath = GetDisplayName(OriginalPath, FullPath); }
public static DirectoryInfo CreateDirectory(String path) { if (path == null) { throw new ArgumentNullException("path"); } if (path.Length == 0) { throw new ArgumentException(SR.Argument_PathEmpty); } Contract.EndContractBlock(); String fullPath = PathHelpers.GetFullPathInternal(path); FileSystem.Current.CreateDirectory(fullPath); return(new DirectoryInfo(fullPath, null)); }
[System.Security.SecurityCritical] // auto-generated public static void SetCurrentDirectory(String path) { if (path == null) { throw new ArgumentNullException("value"); } if (path.Length == 0) { throw new ArgumentException(SR.Argument_PathEmpty); } Contract.EndContractBlock(); if (path.Length >= FileSystem.Current.MaxPath) { throw new PathTooLongException(SR.IO_PathTooLong); } String fulldestDirName = PathHelpers.GetFullPathInternal(path); FileSystem.Current.SetCurrentDirectory(fulldestDirName); }
public void MoveTo(String destFileName) { if (destFileName == null) { throw new ArgumentNullException("destFileName"); } if (destFileName.Length == 0) { throw new ArgumentException(SR.Argument_EmptyFileName, "destFileName"); } Contract.EndContractBlock(); String fullDestFileName = PathHelpers.GetFullPathInternal(destFileName); FileSystem.Current.MoveFile(FullPath, fullDestFileName); FullPath = fullDestFileName; OriginalPath = destFileName; _name = Path.GetFileName(fullDestFileName); DisplayPath = GetDisplayPath(destFileName); // Flush any cached information about the file. Invalidate(); }
public static DirectoryInfo GetParent(String path) { if (path == null) { throw new ArgumentNullException("path"); } if (path.Length == 0) { throw new ArgumentException(SR.Argument_PathEmpty, "path"); } Contract.EndContractBlock(); String fullPath = PathHelpers.GetFullPathInternal(path); String s = Path.GetDirectoryName(fullPath); if (s == null) { return(null); } return(new DirectoryInfo(s)); }
private void Init(String path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options) { if (path == null) { throw new ArgumentNullException("path", SR.ArgumentNull_Path); } if (path.Length == 0) { throw new ArgumentException(SR.Argument_EmptyPath, "path"); } // don't include inheritable in our bounds check for share FileShare tempshare = share & ~FileShare.Inheritable; String badArg = null; if (mode < FileMode.CreateNew || mode > FileMode.Append) { badArg = "mode"; } else if (access < FileAccess.Read || access > FileAccess.ReadWrite) { badArg = "access"; } else if (tempshare < FileShare.None || tempshare > (FileShare.ReadWrite | FileShare.Delete)) { badArg = "share"; } if (badArg != null) { throw new ArgumentOutOfRangeException(badArg, SR.ArgumentOutOfRange_Enum); } // NOTE: any change to FileOptions enum needs to be matched here in the error validation if (options != FileOptions.None && (options & ~(FileOptions.WriteThrough | FileOptions.Asynchronous | FileOptions.RandomAccess | FileOptions.DeleteOnClose | FileOptions.SequentialScan | FileOptions.Encrypted | (FileOptions)0x20000000 /* NoBuffering */)) != 0) { throw new ArgumentOutOfRangeException("options", SR.ArgumentOutOfRange_Enum); } if (bufferSize <= 0) { throw new ArgumentOutOfRangeException("bufferSize", SR.ArgumentOutOfRange_NeedPosNum); } // Write access validation if ((access & FileAccess.Write) == 0) { if (mode == FileMode.Truncate || mode == FileMode.CreateNew || mode == FileMode.Create || mode == FileMode.Append) { // No write access, mode and access disagree but flag access since mode comes first throw new ArgumentException(SR.Format(SR.Argument_InvalidFileModeAndAccessCombo, mode, access), "access"); } } string fullPath = PathHelpers.GetFullPathInternal(path); ValidatePath(fullPath, "path"); if ((access & FileAccess.Read) != 0 && mode == FileMode.Append) { throw new ArgumentException(SR.Argument_InvalidAppendMode, "access"); } this._innerStream = FileSystem.Current.Open(fullPath, mode, access, share, bufferSize, options, this); }
public static DateTime GetLastAccessTime(String path) { String fullPath = PathHelpers.GetFullPathInternal(path); return(FileSystem.Current.GetLastAccessTime(fullPath).LocalDateTime); }
public static void SetCreationTimeUtc(String path, DateTime creationTimeUtc) { String fullPath = PathHelpers.GetFullPathInternal(path); FileSystem.Current.SetCreationTime(fullPath, File.GetUtcDateTimeOffset(creationTimeUtc), asDirectory: true); }
private void Init(String path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options) { if (path == null) { throw new ArgumentNullException("path", SR.ArgumentNull_Path); } if (path.Length == 0) { throw new ArgumentException(SR.Argument_EmptyPath, "path"); } // don't include inheritable in our bounds check for share FileShare tempshare = share & ~FileShare.Inheritable; String badArg = null; if (mode < FileMode.CreateNew || mode > FileMode.Append) { badArg = "mode"; } else if (access < FileAccess.Read || access > FileAccess.ReadWrite) { badArg = "access"; } else if (tempshare < FileShare.None || tempshare > (FileShare.ReadWrite | FileShare.Delete)) { badArg = "share"; } if (badArg != null) { throw new ArgumentOutOfRangeException(badArg, SR.ArgumentOutOfRange_Enum); } // NOTE: any change to FileOptions enum needs to be matched here in the error validation if (options != FileOptions.None && (options & ~(FileOptions.WriteThrough | FileOptions.Asynchronous | FileOptions.RandomAccess | FileOptions.DeleteOnClose | FileOptions.SequentialScan | FileOptions.Encrypted | (FileOptions)0x20000000 /* NoBuffering */)) != 0) { throw new ArgumentOutOfRangeException("options", SR.ArgumentOutOfRange_Enum); } if (bufferSize <= 0) { throw new ArgumentOutOfRangeException("bufferSize", SR.ArgumentOutOfRange_NeedPosNum); } // Write access validation if ((access & FileAccess.Write) == 0) { if (mode == FileMode.Truncate || mode == FileMode.CreateNew || mode == FileMode.Create || mode == FileMode.Append) { // No write access throw new ArgumentException(SR.Format(SR.Argument_InvalidFileModeAndAccessCombo, mode, access)); } } string fullPath = PathHelpers.GetFullPathInternal(path); // Prevent access to your disk drives as raw block devices. if (fullPath.StartsWith("\\\\.\\", StringComparison.Ordinal)) { throw new ArgumentException(SR.Arg_DevicesNotSupported); } #if !PLATFORM_UNIX // Check for additional invalid characters. Most invalid characters were checked above // in our call to Path.GetFullPath(path); if (HasAdditionalInvalidCharacters(fullPath)) { throw new ArgumentException(SR.Argument_InvalidPathChars); } if (fullPath.IndexOf(':', 2) != -1) { throw new NotSupportedException(SR.Argument_PathFormatNotSupported); } #endif if ((access & FileAccess.Read) != 0 && mode == FileMode.Append) { throw new ArgumentException(SR.Argument_InvalidAppendMode); } this._innerStream = FileSystem.Current.Open(fullPath, mode, access, share, bufferSize, options, this); }
public static void SetLastWriteTime(String path, DateTime lastWriteTime) { String fullPath = PathHelpers.GetFullPathInternal(path); FileSystem.Current.SetLastWriteTime(fullPath, lastWriteTime, asDirectory: true); }
public static void SetLastAccessTimeUtc(String path, DateTime lastAccessTime) { String fullPath = PathHelpers.GetFullPathInternal(path); FileSystem.Current.SetLastAccessTime(fullPath, File.GetUtcDateTimeOffset(lastAccessTime), asDirectory: true); }
public static void SetCreationTime(String path, DateTime creationTimeUtc) { String fullPath = PathHelpers.GetFullPathInternal(path); FileSystem.Current.SetCreationTime(fullPath, creationTimeUtc, asDirectory: false); }
public static DateTime GetCreationTime(String path) { String fullPath = PathHelpers.GetFullPathInternal(path); return(FileSystem.Current.GetCreationTime(fullPath).DateTime); }
public static void SetLastWriteTimeUtc(String path, DateTime lastWriteTimeUtc) { String fullPath = PathHelpers.GetFullPathInternal(path); FileSystem.Current.SetLastWriteTime(fullPath, GetUtcDateTimeOffset(lastWriteTimeUtc), asDirectory: false); }
public static void SetAttributes(String path, FileAttributes fileAttributes) { String fullPath = PathHelpers.GetFullPathInternal(path); FileSystem.Current.SetAttributes(fullPath, fileAttributes); }
public static void Delete(String path, bool recursive) { String fullPath = PathHelpers.GetFullPathInternal(path); FileSystem.Current.RemoveDirectory(fullPath, recursive); }
[System.Security.SecuritySafeCritical] // auto-generated public static DateTime GetLastWriteTimeUtc(String path) { String fullPath = PathHelpers.GetFullPathInternal(path); return(FileSystem.Current.GetLastWriteTime(fullPath).UtcDateTime); }
public static FileAttributes GetAttributes(String path) { String fullPath = PathHelpers.GetFullPathInternal(path); return(FileSystem.Current.GetAttributes(fullPath)); }