using System; using System.Runtime.InteropServices; using System.Runtime.Serialization; namespace System.IO { /// Provides instance methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of objects. This class cannot be inherited. /// 1 // Token: 0x020001B5 RID: 437 [ComVisible(true)] [Serializable] public sealed class FileInfo : FileSystemInfo { /// Initializes a new instance of the class, which acts as a wrapper for a file path. /// The fully qualified name of the new file, or the relative file name. /// /// is null. /// The caller does not have the required permission. /// The file name is empty, contains only white spaces, or contains invalid characters. /// Access to is denied. /// The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. /// /// contains a colon (:) in the middle of the string. // Token: 0x06001667 RID: 5735 RVA: 0x0005649C File Offset: 0x0005469C public FileInfo(string fileName) { if (fileName == null) { throw new ArgumentNullException("fileName"); } base.CheckPath(fileName); this.OriginalPath = fileName; this.FullPath = Path.GetFullPath(fileName); } // Token: 0x06001668 RID: 5736 RVA: 0x000564D0 File Offset: 0x000546D0 private FileInfo(SerializationInfo info, StreamingContext context) : base(info, context) { } // Token: 0x06001669 RID: 5737 RVA: 0x000564DC File Offset: 0x000546DC internal override void InternalRefresh() { this.exists = File.Exists(this.FullPath); } /// Gets a value indicating whether a file exists. /// true if the file exists; false if the file does not exist or if the file is a directory. /// 1 // Token: 0x170003EC RID: 1004 // (get) Token: 0x0600166A RID: 5738 RVA: 0x000564F0 File Offset: 0x000546F0 public override bool Exists { get { base.Refresh(false); return this.stat.Attributes != MonoIO.InvalidFileAttributes && (this.stat.Attributes & FileAttributes.Directory) == (FileAttributes)0 && this.exists; } } /// Gets the name of the file. /// The name of the file. /// 1 // Token: 0x170003ED RID: 1005 // (get) Token: 0x0600166B RID: 5739 RVA: 0x0005652C File Offset: 0x0005472C public override string Name { get { return Path.GetFileName(this.FullPath); } } /// Gets or sets a value that determines if the current file is read only. /// true if the current file is read only; otherwise, false. /// The file described by the current object could not be found. /// An I/O error occurred while opening the file. /// The file described by the current object is read-only.-or- This operation is not supported on the current platform.-or- The caller does not have the required permission. /// 1 // Token: 0x170003EE RID: 1006 // (get) Token: 0x0600166C RID: 5740 RVA: 0x0005653C File Offset: 0x0005473C // (set) Token: 0x0600166D RID: 5741 RVA: 0x00056588 File Offset: 0x00054788 public bool IsReadOnly { get { if (!this.Exists) { throw new FileNotFoundException("Could not find file \"" + this.OriginalPath + "\".", this.OriginalPath); } return (this.stat.Attributes & FileAttributes.ReadOnly) != (FileAttributes)0; } set { if (!this.Exists) { throw new FileNotFoundException("Could not find file \"" + this.OriginalPath + "\".", this.OriginalPath); } FileAttributes fileAttributes = File.GetAttributes(this.FullPath); if (value) { fileAttributes |= FileAttributes.ReadOnly; } else { fileAttributes &= ~FileAttributes.ReadOnly; } File.SetAttributes(this.FullPath, fileAttributes); } } /// Encrypts a file so that only the account used to encrypt the file can decrypt it. /// An invalid drive was specified. /// The file described by the current object could not be found. /// An I/O error occurred while opening the file. /// The file system is not NTFS. /// The current operating system is not Microsoft Windows NT or later. /// The file described by the current object is read-only.-or- This operation is not supported on the current platform.-or- The caller does not have the required permission. /// 1 /// /// /// // Token: 0x0600166E RID: 5742 RVA: 0x000565F0 File Offset: 0x000547F0 [ComVisible(false)] [MonoLimitation("File encryption isn't supported (even on NTFS).")] public void Encrypt() { throw new NotSupportedException(Locale.GetText("File encryption isn't supported on any file system.")); } /// Decrypts a file that was encrypted by the current account using the method. /// An invalid drive was specified. /// The file described by the current object could not be found. /// An I/O error occurred while opening the file. /// The file system is not NTFS. /// The current operating system is not Microsoft Windows NT or later. /// The file described by the current object is read-only.-or- This operation is not supported on the current platform.-or- The caller does not have the required permission. /// 2 /// /// /// // Token: 0x0600166F RID: 5743 RVA: 0x00056604 File Offset: 0x00054804 [MonoLimitation("File encryption isn't supported (even on NTFS).")] [ComVisible(false)] public void Decrypt() { throw new NotSupportedException(Locale.GetText("File encryption isn't supported on any file system.")); } /// Gets the size, in bytes, of the current file. /// The size of the current file in bytes. /// /// cannot update the state of the file or directory. /// The file does not exist.-or- The Length property is called for a directory. /// 1 // Token: 0x170003EF RID: 1007 // (get) Token: 0x06001670 RID: 5744 RVA: 0x00056618 File Offset: 0x00054818 public long Length { get { if (!this.Exists) { throw new FileNotFoundException("Could not find file \"" + this.OriginalPath + "\".", this.OriginalPath); } return this.stat.Length; } } /// Gets a string representing the directory's full path. /// A string representing the directory's full path. /// null was passed in for the directory name. /// The fully qualified path is 260 or more characters. /// The caller does not have the required permission. /// 1 /// /// /// // Token: 0x170003F0 RID: 1008 // (get) Token: 0x06001671 RID: 5745 RVA: 0x00056654 File Offset: 0x00054854 public string DirectoryName { get { return Path.GetDirectoryName(this.FullPath); } } /// Gets an instance of the parent directory. /// A object representing the parent directory of this file. /// The specified path is invalid, such as being on an unmapped drive. /// The caller does not have the required permission. /// 1 /// /// /// // Token: 0x170003F1 RID: 1009 // (get) Token: 0x06001672 RID: 5746 RVA: 0x00056664 File Offset: 0x00054864 public DirectoryInfo Directory { get { return new DirectoryInfo(this.DirectoryName); } } /// Creates a with UTF8 encoding that reads from an existing text file. /// A new StreamReader with UTF8 encoding. /// The caller does not have the required permission. /// The file is not found. /// /// is read-only or is a directory. /// The specified path is invalid, such as being on an unmapped drive. /// 2 /// /// /// // Token: 0x06001673 RID: 5747 RVA: 0x00056674 File Offset: 0x00054874 public StreamReader OpenText() { return new StreamReader(this.Open(FileMode.Open, FileAccess.Read)); } /// Creates a that writes a new text file. /// A new StreamWriter. /// The file name is a directory. /// The disk is read-only. /// The caller does not have the required permission. /// 1 /// /// /// // Token: 0x06001674 RID: 5748 RVA: 0x00056684 File Offset: 0x00054884 public StreamWriter CreateText() { return new StreamWriter(this.Open(FileMode.Create, FileAccess.Write)); } /// Creates a that appends text to the file represented by this instance of the . /// A new StreamWriter. /// 1 /// /// /// // Token: 0x06001675 RID: 5749 RVA: 0x00056694 File Offset: 0x00054894 public StreamWriter AppendText() { return new StreamWriter(this.Open(FileMode.Append, FileAccess.Write)); } /// Creates a file. /// A new file. /// 1 /// /// /// // Token: 0x06001676 RID: 5750 RVA: 0x000566A4 File Offset: 0x000548A4 public FileStream Create() { return File.Create(this.FullPath); } /// Creates a read-only . /// A new read-only object. /// /// is read-only or is a directory. /// The specified path is invalid, such as being on an unmapped drive. /// The file is already open. /// 2 /// /// /// // Token: 0x06001677 RID: 5751 RVA: 0x000566B4 File Offset: 0x000548B4 public FileStream OpenRead() { return this.Open(FileMode.Open, FileAccess.Read, FileShare.Read); } /// Creates a write-only . /// A new write-only unshared object. /// /// is read-only or is a directory. /// The specified path is invalid, such as being on an unmapped drive. /// 2 /// /// /// // Token: 0x06001678 RID: 5752 RVA: 0x000566C0 File Offset: 0x000548C0 public FileStream OpenWrite() { return this.Open(FileMode.OpenOrCreate, FileAccess.Write); } /// Opens a file in the specified mode. /// A file opened in the specified mode, with read/write access and unshared. /// A constant specifying the mode (for example, Open or Append) in which to open the file. /// The file is not found. /// The file is read-only or is a directory. /// The specified path is invalid, such as being on an unmapped drive. /// The file is already open. /// 2 /// /// /// // Token: 0x06001679 RID: 5753 RVA: 0x000566CC File Offset: 0x000548CC public FileStream Open(FileMode mode) { return this.Open(mode, FileAccess.ReadWrite); } /// Opens a file in the specified mode with read, write, or read/write access. /// A object opened in the specified mode and access, and unshared. /// A constant specifying the mode (for example, Open or Append) in which to open the file. /// A constant specifying whether to open the file with Read, Write, or ReadWrite file access. /// The caller does not have the required permission. /// /// is empty or contains only white spaces. /// The file is not found. /// One or more arguments is null. /// /// is read-only or is a directory. /// The specified path is invalid, such as being on an unmapped drive. /// The file is already open. /// 2 /// /// /// // Token: 0x0600167A RID: 5754 RVA: 0x000566D8 File Offset: 0x000548D8 public FileStream Open(FileMode mode, FileAccess access) { return this.Open(mode, access, FileShare.None); } /// Opens a file in the specified mode with read, write, or read/write access and the specified sharing option. /// A object opened with the specified mode, access, and sharing options. /// A constant specifying the mode (for example, Open or Append) in which to open the file. /// A constant specifying whether to open the file with Read, Write, or ReadWrite file access. /// A constant specifying the type of access other FileStream objects have to this file. /// The caller does not have the required permission. /// /// is empty or contains only white spaces. /// The file is not found. /// One or more arguments is null. /// /// is read-only or is a directory. /// The specified path is invalid, such as being on an unmapped drive. /// The file is already open. /// 2 /// /// /// // Token: 0x0600167B RID: 5755 RVA: 0x000566E4 File Offset: 0x000548E4 public FileStream Open(FileMode mode, FileAccess access, FileShare share) { return new FileStream(this.FullPath, mode, access, share); } /// Permanently deletes a file. /// The target file is open or memory-mapped on a computer running Microsoft Windows NT. /// The caller does not have the required permission. /// The path is a directory. /// 1 /// /// /// // Token: 0x0600167C RID: 5756 RVA: 0x000566F4 File Offset: 0x000548F4 public override void Delete() { MonoIOError monoIOError; if (!MonoIO.Exists(this.FullPath, out monoIOError)) { return; } if (MonoIO.ExistsDirectory(this.FullPath, out monoIOError)) { throw new UnauthorizedAccessException("Access to the path \"" + this.FullPath + "\" is denied."); } if (!MonoIO.DeleteFile(this.FullPath, out monoIOError)) { throw MonoIO.GetException(this.OriginalPath, monoIOError); } } /// Moves a specified file to a new location, providing the option to specify a new file name. /// The path to move the file to, which can specify a different file name. /// An I/O error occurs, such as the destination file already exists or the destination device is not ready. /// /// is null. /// /// is empty, contains only white spaces, or contains invalid characters. /// The caller does not have the required permission. /// /// is read-only or is a directory. /// The file is not found. /// The specified path is invalid, such as being on an unmapped drive. /// The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. /// /// contains a colon (:) in the middle of the string. /// 1 /// /// /// // Token: 0x0600167D RID: 5757 RVA: 0x00056760 File Offset: 0x00054960 public void MoveTo(string destFileName) { if (destFileName == null) { throw new ArgumentNullException("destFileName"); } if (destFileName == this.Name || destFileName == this.FullName) { return; } if (!File.Exists(this.FullPath)) { throw new FileNotFoundException(); } File.Move(this.FullPath, destFileName); this.FullPath = Path.GetFullPath(destFileName); } /// Copies an existing file to a new file, disallowing the overwriting of an existing file. /// A new file with a fully qualified path. /// The name of the new file to copy to. /// /// is empty, contains only white spaces, or contains invalid characters. /// An error occurs, or the destination file already exists. /// The caller does not have the required permission. /// /// is null. /// A directory path is passed in, or the file is being moved to a different drive. /// The directory specified in does not exist. /// The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. /// /// contains a colon (:) within the string but does not specify the volume. /// 1 /// /// /// // Token: 0x0600167E RID: 5758 RVA: 0x000567D0 File Offset: 0x000549D0 public FileInfo CopyTo(string destFileName) { return this.CopyTo(destFileName, false); } /// Copies an existing file to a new file, allowing the overwriting of an existing file. /// A new file, or an overwrite of an existing file if is true. If the file exists and is false, an is thrown. /// The name of the new file to copy to. /// true to allow an existing file to be overwritten; otherwise, false. /// /// is empty, contains only white spaces, or contains invalid characters. /// An error occurs, or the destination file already exists and is false. /// The caller does not have the required permission. /// /// is null. /// The directory specified in does not exist. /// A directory path is passed in, or the file is being moved to a different drive. /// The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. /// /// contains a colon (:) in the middle of the string. /// 1 /// /// /// // Token: 0x0600167F RID: 5759 RVA: 0x000567DC File Offset: 0x000549DC public FileInfo CopyTo(string destFileName, bool overwrite) { if (destFileName == null) { throw new ArgumentNullException("destFileName"); } if (destFileName.Length == 0) { throw new ArgumentException("An empty file name is not valid.", "destFileName"); } string fullPath = Path.GetFullPath(destFileName); if (overwrite && File.Exists(fullPath)) { File.Delete(fullPath); } File.Copy(this.FullPath, fullPath); return new FileInfo(fullPath); } /// Returns the path as a string. /// A string representing the path. /// 1 // Token: 0x06001680 RID: 5760 RVA: 0x00056848 File Offset: 0x00054A48 public override string ToString() { return this.Name; } /// Replaces the contents of a specified file with the file described by the current object, deleting the original file, and creating a backup of the replaced file. /// A object that encapsulates information about the file described by the parameter. /// The name of a file to replace with the current file. /// The name of a file with which to create a backup of the file described by the parameter. /// The path described by the parameter was not of a legal form.-or-The path described by the parameter was not of a legal form. /// The parameter is null. /// The file described by the current object could not be found.-or-The file described by the parameter could not be found. /// The current operating system is not Microsoft Windows NT or later. /// 2 /// /// /// // Token: 0x06001681 RID: 5761 RVA: 0x00056850 File Offset: 0x00054A50 [ComVisible(false)] public FileInfo Replace(string destinationFileName, string destinationBackupFileName) { if (!this.Exists) { throw new FileNotFoundException(); } if (destinationFileName == null) { throw new ArgumentNullException("destinationFileName"); } if (destinationFileName.Length == 0) { throw new ArgumentException("An empty file name is not valid.", "destinationFileName"); } string fullPath = Path.GetFullPath(destinationFileName); if (!File.Exists(fullPath)) { throw new FileNotFoundException(); } FileAttributes attributes = File.GetAttributes(fullPath); if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { throw new UnauthorizedAccessException(); } if (destinationBackupFileName != null) { if (destinationBackupFileName.Length == 0) { throw new ArgumentException("An empty file name is not valid.", "destinationBackupFileName"); } File.Copy(fullPath, Path.GetFullPath(destinationBackupFileName), true); } File.Copy(this.FullPath, fullPath, true); File.Delete(this.FullPath); return new FileInfo(fullPath); } /// Replaces the contents of a specified file with the file described by the current object, deleting the original file, and creating a backup of the replaced file. Also specifies whether to ignore merge errors. /// A object that encapsulates information about the file described by the parameter. /// The name of a file to replace with the current file. /// The name of a file with which to create a backup of the file described by the parameter. /// true to ignore merge errors (such as attributes and ACLs) from the replaced file to the replacement file; otherwise false. /// The path described by the parameter was not of a legal form.-or-The path described by the parameter was not of a legal form. /// The parameter is null. /// The file described by the current object could not be found.-or-The file described by the parameter could not be found. /// The current operating system is not Microsoft Windows NT or later. /// 2 /// /// /// // Token: 0x06001682 RID: 5762 RVA: 0x00056918 File Offset: 0x00054B18 [ComVisible(false)] public FileInfo Replace(string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors) { throw new NotImplementedException(); } // Token: 0x0400066E RID: 1646 private bool exists; } }