public ref class FileSystemInfo abstract
public ref class FileSystemInfo abstract : MarshalByRefObject, System::Runtime::Serialization::ISerializable
public abstract class FileSystemInfo
public abstract class FileSystemInfo : MarshalByRefObject, System.Runtime.Serialization.ISerializable
[System.Serializable]
public abstract class FileSystemInfo : MarshalByRefObject, System.Runtime.Serialization.ISerializable
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class FileSystemInfo : MarshalByRefObject, System.Runtime.Serialization.ISerializable
type FileSystemInfo = class
type FileSystemInfo = class
inherit MarshalByRefObject
interface ISerializable
[<System.Serializable>]
type FileSystemInfo = class
inherit MarshalByRefObject
interface ISerializable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type FileSystemInfo = class
inherit MarshalByRefObject
interface ISerializable
Public MustInherit Class FileSystemInfo
Public MustInherit Class FileSystemInfo
Inherits MarshalByRefObject
Implements ISerializable
The following example shows how to loop through all the files and directories, querying some information about each entry.
using System;
using System.IO;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
// Loop through all the immediate subdirectories of C.
foreach (string entry in Directory.GetDirectories(@"C:\"))
{
DisplayFileSystemInfoAttributes(new DirectoryInfo(entry));
}
// Loop through all the files in C.
foreach (string entry in Directory.GetFiles(@"C:\"))
{
DisplayFileSystemInfoAttributes(new FileInfo(entry));
}
}
static void DisplayFileSystemInfoAttributes(FileSystemInfo fsi)
{
// Assume that this entry is a file.
string entryType = "File";
// Determine if entry is really a directory
if ((fsi.Attributes & FileAttributes.Directory) == FileAttributes.Directory )
{
entryType = "Directory";
}
// Show this entry's type, name, and creation date.
Console.WriteLine("{0} entry {1} was created on {2:D}", entryType, fsi.FullName, fsi.CreationTime);
}
}
}
// Output will vary based on contents of drive C.
// Directory entry C:\Documents and Settings was created on Tuesday, November 25, 2003
// Directory entry C:\Inetpub was created on Monday, January 12, 2004
// Directory entry C:\Program Files was created on Tuesday, November 25, 2003
// Directory entry C:\RECYCLER was created on Tuesday, November 25, 2003
// Directory entry C:\System Volume Information was created on Tuesday, November 2, 2003
// Directory entry C:\WINDOWS was created on Tuesday, November 25, 2003
// File entry C:\IO.SYS was created on Tuesday, November 25, 2003
// File entry C:\MSDOS.SYS was created on Tuesday, November 25, 2003
// File entry C:\pagefile.sys was created on Saturday, December 27, 2003
Imports System.IO
Module Module1
Sub Main()
' Loop through all the immediate subdirectories of C.
For Each entry As String In Directory.GetDirectories("C:\")
DisplayFileSystemInfoAttributes(New DirectoryInfo(entry))
Next
' Loop through all the files in C.
For Each entry As String In Directory.GetFiles("C:\")
DisplayFileSystemInfoAttributes(New FileInfo(entry))
Next
End Sub
Sub DisplayFileSystemInfoAttributes(ByVal fsi As IO.FileSystemInfo)
' Assume that this entry is a file.
Dim entryType As String = "File"
' Determine if this entry is really a directory.
If (fsi.Attributes And FileAttributes.Directory) = FileAttributes.Directory Then
entryType = "Directory"
End If
' Show this entry's type, name, and creation date.
Console.WriteLine("{0} entry {1} was created on {2:D}", _
entryType, fsi.FullName, fsi.CreationTime)
End Sub
End Module
' Output will vary based on contents of drive C.
'
' Directory entry C:\Documents and Settings was created on Tuesday, November 25, 2003
' Directory entry C:\Inetpub was created on Monday, January 12, 2004
' Directory entry C:\Program Files was created on Tuesday, November 25, 2003
' Directory entry C:\RECYCLER was created on Tuesday, November 25, 2003
' Directory entry C:\System Volume Information was created on Tuesday, November 2, 2003
' Directory entry C:\WINDOWS was created on Tuesday, November 25, 2003
' File entry C:\IO.SYS was created on Tuesday, November 25, 2003
' File entry C:\MSDOS.SYS was created on Tuesday, November 25, 2003
' File entry C:\pagefile.sys was created on Saturday, December 27, 2003
The FileSystemInfo class contains methods that are common to file and directory manipulation. A FileSystemInfo object can represent either a file or a directory, thus serving as the basis for FileInfo or DirectoryInfo objects. Use this base class when parsing a lot of files and directories.
A derived class can inherit from FileSystemInfo only if the derived class has the AllAccess permission from the FileIOPermissionAccess enumeration.
In members that accept a path, the path can refer to a file or just a directory. The specified path can also refer to a relative path or a Universal Naming Convention (UNC) path for a server and share name. For example, all the following are acceptable paths:
"c:\\MyDir\\MyFile.txt" in C#, or "c:\MyDir\MyFile.txt" in Visual Basic.
"c:\\MyDir" in C#, or "c:\MyDir" in Visual Basic.
"MyDir\\MySubdir" in C#, or "MyDir\MySubDir" in Visual Basic.
"\\\\MyServer\\MyShare" in C#, or "\\MyServer\MyShare" in Visual Basic.
For a list of common I/O tasks, see Common I/O Tasks.
Constructors Fields FullPathRepresents the fully qualified path of the directory or file.
OriginalPathThe path originally specified by the user, whether relative or absolute.
Properties AttributesGets or sets the attributes for the current file or directory.
CreationTimeGets or sets the creation time of the current file or directory.
CreationTimeUtcGets or sets the creation time, in coordinated universal time (UTC), of the current file or directory.
ExistsGets a value indicating whether the file or directory exists.
ExtensionGets the extension part of the file name, including the leading dot .
even if it is the entire file name, or an empty string if no extension is present.
Gets the full path of the directory or file.
LastAccessTimeGets or sets the time the current file or directory was last accessed.
LastAccessTimeUtcGets or sets the time, in coordinated universal time (UTC), that the current file or directory was last accessed.
LastWriteTimeGets or sets the time when the current file or directory was last written to.
LastWriteTimeUtcGets or sets the time, in coordinated universal time (UTC), when the current file or directory was last written to.
LinkTargetGets the target path of the link located in FullName, or null
if this FileSystemInfo instance doesn't represent a link.
For files, gets the name of the file. For directories, gets the name of the last directory in the hierarchy if a hierarchy exists. Otherwise, the Name
property gets the name of the directory.
Gets or sets the Unix file mode for the current file or directory.
Methods See alsoRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4