public static void SetLastAccessTime(string path, DateTime lastAccessTime) { MonoIOError error; Path.Validate(path); if (!MonoIO.Exists(path, out error)) { throw MonoIO.GetException(path, error); } if (!MonoIO.SetLastAccessTime(path, lastAccessTime, out error)) { throw MonoIO.GetException(path, error); } }
public static void SetCreationTime(string path, DateTime creationTime) { MonoIOError error; CheckPathExceptions(path); if (!MonoIO.Exists(path, out error)) { throw MonoIO.GetException(path, error); } if (!MonoIO.SetCreationTime(path, creationTime, out error)) { throw MonoIO.GetException(path, error); } }
/// <summary>Permanently deletes a file.</summary> /// <exception cref="T:System.IO.IOException">The target file is open or memory-mapped on a computer running Microsoft Windows NT. </exception> /// <exception cref="T:System.Security.SecurityException">The caller does not have the required permission. </exception> /// <exception cref="T:System.UnauthorizedAccessException">The path is a directory. </exception> /// <filterpriority>1</filterpriority> /// <PermissionSet> /// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /> /// </PermissionSet> public override void Delete() { MonoIOError error; if (!MonoIO.Exists(this.FullPath, out error)) { return; } if (MonoIO.ExistsDirectory(this.FullPath, out error)) { throw new UnauthorizedAccessException("Access to the path \"" + this.FullPath + "\" is denied."); } if (!MonoIO.DeleteFile(this.FullPath, out error)) { throw MonoIO.GetException(this.OriginalPath, error); } }
// file methods public override void Delete() { MonoIOError error; if (!MonoIO.Exists(FullPath, out error)) { // a weird MS.NET behaviour return; } if (MonoIO.ExistsDirectory(FullPath, out error)) { throw new UnauthorizedAccessException("Access to the path \"" + FullPath + "\" is denied."); } if (!MonoIO.DeleteFile(FullPath, out error)) { throw MonoIO.GetException(OriginalPath, error); } }
// file methods public override void Delete() { MonoIOError error; SecurityManager.EnsureElevatedPermissions(); // this is a no-op outside moonlight if (!MonoIO.Exists(FullPath, out error)) { // a weird MS.NET behaviour return; } if (MonoIO.ExistsDirectory(FullPath, out error)) { throw new UnauthorizedAccessException("Access to the path \"" + FullPath + "\" is denied."); } if (!MonoIO.DeleteFile(FullPath, out error)) { throw MonoIO.GetException(OriginalPath, error); } }
public static void Copy(string sourceFileName, string destFileName, bool overwrite) { MonoIOError error; if (sourceFileName == null) { throw new ArgumentNullException("sourceFileName"); } if (destFileName == null) { throw new ArgumentNullException("destFileName"); } if (sourceFileName.Length == 0) { throw new ArgumentException("An empty file name is not valid.", "sourceFileName"); } if (sourceFileName.Trim().Length == 0 || sourceFileName.IndexOfAny(Path.InvalidPathChars) != -1) { throw new ArgumentException("The file name is not valid."); } if (destFileName.Length == 0) { throw new ArgumentException("An empty file name is not valid.", "destFileName"); } if (destFileName.Trim().Length == 0 || destFileName.IndexOfAny(Path.InvalidPathChars) != -1) { throw new ArgumentException("The file name is not valid."); } SecurityManager.EnsureElevatedPermissions(); // this is a no-op outside moonlight if (!MonoIO.Exists(sourceFileName, out error)) { throw new FileNotFoundException(Locale.GetText("{0} does not exist", sourceFileName), sourceFileName); } if ((GetAttributes(sourceFileName) & FileAttributes.Directory) == FileAttributes.Directory) { throw new ArgumentException(Locale.GetText("{0} is a directory", sourceFileName)); } if (MonoIO.Exists(destFileName, out error)) { if ((GetAttributes(destFileName) & FileAttributes.Directory) == FileAttributes.Directory) { throw new ArgumentException(Locale.GetText("{0} is a directory", destFileName)); } if (!overwrite) { throw new IOException(Locale.GetText("{0} already exists", destFileName)); } } string DirName = Path.GetDirectoryName(destFileName); if (DirName != String.Empty && !Directory.Exists(DirName)) { throw new DirectoryNotFoundException(Locale.GetText("Destination directory not found: {0}", DirName)); } if (!MonoIO.CopyFile(sourceFileName, destFileName, overwrite, out error)) { string p = Locale.GetText("{0}\" or \"{1}", sourceFileName, destFileName); throw MonoIO.GetException(p, error); } }
public static void Move(string sourceFileName, string destFileName) { if (sourceFileName == null) { throw new ArgumentNullException("sourceFileName"); } if (destFileName == null) { throw new ArgumentNullException("destFileName"); } if (sourceFileName.Length == 0) { throw new ArgumentException("An empty file name is not valid.", "sourceFileName"); } if (sourceFileName.Trim().Length == 0 || sourceFileName.IndexOfAny(Path.InvalidPathChars) != -1) { throw new ArgumentException("The file name is not valid."); } if (destFileName.Length == 0) { throw new ArgumentException("An empty file name is not valid.", "destFileName"); } if (destFileName.Trim().Length == 0 || destFileName.IndexOfAny(Path.InvalidPathChars) != -1) { throw new ArgumentException("The file name is not valid."); } SecurityManager.EnsureElevatedPermissions(); // this is a no-op outside moonlight MonoIOError error; if (!MonoIO.Exists(sourceFileName, out error)) { throw new FileNotFoundException(Locale.GetText("{0} does not exist", sourceFileName), sourceFileName); } // Don't check for this error here to allow the runtime // to check if sourceFileName and destFileName are equal. // Comparing sourceFileName and destFileName is not enough. //if (MonoIO.Exists (destFileName, out error)) // throw new IOException (Locale.GetText ("{0} already exists", destFileName)); string DirName; DirName = Path.GetDirectoryName(destFileName); if (DirName != String.Empty && !Directory.Exists(DirName)) { throw new DirectoryNotFoundException(Locale.GetText("Could not find a part of the path.")); } if (!MonoIO.MoveFile(sourceFileName, destFileName, out error)) { if (error == MonoIOError.ERROR_ALREADY_EXISTS) { throw MonoIO.GetException(error); } else if (error == MonoIOError.ERROR_SHARING_VIOLATION) { throw MonoIO.GetException(sourceFileName, error); } throw MonoIO.GetException(error); } }