System.IO.Directory Class

Assembly: Mscorlib.dll
Namespace: System.IO
Summary
Exposes static methods for creating, moving, and enumerating through directories and subdirectories.
C# Syntax:
public sealed class Directory
Remarks
All methods of the Directory class are static and can therefore be called without having an instance of a directory. The DirectoryInfo class contains only instance methods. The static methods of the Directory class perform a security check on all methods. If you are going to reuse an object several times, consider using the corresponding instance method of DirectoryInfo instead, because the security check will not always be necessary.

Note In members that accept a path as an input string, that path must be well-formed or an exception is raised. For example, if a path is fully qualified but begins with a space, the path is not trimmed in methods of the class. Therefore, the path is malformed and an exception is raised. Similarly, a path or a combination of paths cannot be fully qualified twice. For example, "c:\temp c:\windows" also raises an exception in most cases. Ensure that your paths are well-formed when using methods that accept a path string.

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 of the following are acceptable paths:

By default, full read/write access to new directories is granted to all users.

See also:
System.IO Namespace | File | DirectoryInfo | FileInfo

System.IO.Directory Member List:

Public Methods
CreateDirectory Creates all directories and subdirectories as specified by path.
Delete Overloaded:
Delete(string path)

Deletes an empty directory from a specified path.
Delete Overloaded:
Delete(string path, bool recursive)

Deletes the specified directory and, if indicated, any subdirectories in the directory.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
Exists Determines whether the given path refers to an existing directory on disk.
GetCreationTime Gets the creation date and time of a directory.
GetCurrentDirectory Gets the current working directory of the application.
GetDirectories Overloaded:
GetDirectories(string path)

Gets the names of subdirectories in the specified directory.
GetDirectories Overloaded:
GetDirectories(string path, string searchPattern)

Gets an array of directories matching the specified search pattern from the current directory.
GetDirectoryRoot Returns the volume information, root information, or both for the specified path.
GetFiles Overloaded:
GetFiles(string path)

Returns the names of files in the specified directory.
GetFiles Overloaded:
GetFiles(string path, string searchPattern)

Returns the names of files in the specified directory that match the specified search pattern.
GetFileSystemEntries Overloaded:
GetFileSystemEntries(string path)

Returns the names of all files and subdirectories in the specified directory.
GetFileSystemEntries Overloaded:
GetFileSystemEntries(string path, string searchPattern)

Returns an array of file system entries matching the specified search criteria.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetLastAccessTime Returns the date and time the specified file or directory was last accessed.
GetLastWriteTime Returns the date and time the specified file or directory was last written to.
GetLogicalDrives Retrieves the names of the logical drives on this computer in the form "<drive letter>:\".
GetParent Retrieves the parent directory of the specified path, including both absolute and relative paths.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
Move Moves a file or a directory and its contents to a new location.
SetCreationTime Sets the creation date and time for the specified file or directory.
SetCurrentDirectory Sets the application's current working directory to the specified directory.
SetLastAccessTime Sets the date and time the specified file or directory was last accessed.
SetLastWriteTime Sets the date and time a directory was last written to.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.IO.Directory Member Details

Method: CreateDirectory(
   string path
)
Summary
Creates all directories and subdirectories as specified by path.
C# Syntax:
public static DirectoryInfo CreateDirectory(
   string path
);
Parameters:

path

The directory path to create.

Return Value:
All DirectoryInfo objects, including subdirectories, specified by path.
Exceptions
Exception Type Condition
IOException The directory specified by path is read-only or is not empty.
SecurityException The caller does not have the required permission.
ArgumentException path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.InvalidPathChars.
ArgumentNullException path is null.
PathTooLongException The length of path or the absolute path information for path exceeds the system-defined maximum length.
DirectoryNotFoundException The specified path was not found.
NotSupportedException Creating a directory with only the colon (:) character was attempted.
Remarks
By default, full read/write access to new directories is granted to all users.

Any and all directories specified in path are created, unless they already exist or unless some part of path is invalid. The path parameter specifies a directory path, not a file path.

Creating a directory with only the colon (:) character is not supported, and will cause a NotSupportedException to be thrown.



Note Path names are limited to the length allowed by the platform.
Example
To create the directory C:\Users\User1\Public\Html when the current directory is C:\Users\User1, use any of the following calls to ensure that the backslash is interpreted properly.

In Visual Basic:

              				Directory.CreateDirectory("Public\Html") 
              				Directory.CreateDirectory("\Users\User1\Public\Html") 
              				Directory.CreateDirectory("c:\Users\User1\Public\Html") 
              			
            

In C# or C++:

              				Directory::CreateDirectory("Public\\Html");
              				Directory::CreateDirectory("\\Users\\User1\\Public\\Html");
              				Directory::CreateDirectory("c:\\Users\\User1\\Public\\Html");
              			
            
.NET Framework Security:
FileIOPermission for reading from files or directories. Associated enumeration: FileIOPermissionAccess.Read
See also:
DirectoryInfo

Return to top


Overloaded Method: Delete(
   string path
)
Summary
Deletes an empty directory from a specified path.
C# Syntax:
public static void Delete(
   string path
);
Parameters:

path

The fully qualified name of the empty directory to remove. This directory must be writable or empty.

Exceptions
Exception Type Condition
IOException The directory specified by path is read-only or is not empty.
SecurityException The caller does not have the required permission.
ArgumentException path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.InvalidPathChars.
ArgumentNullException path is null.
PathTooLongException The length of path or the absolute path information for path exceeds the system-defined maximum length.
DirectoryNotFoundException The specified path was not found.
Remarks
This method behaves identically to Delete.

The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see Directory.GetCurrentDirectory.

This method throws an IOException if the directory specified in the path parameter contains files or subdirectories.

The path parameter is not case-sensitive.

.NET Framework Security:
FileIOPermission for writing to the specified directory. Associated enumeration: FileIOPermissionAccess.Write

Return to top


Overloaded Method: Delete(
   string path,
   bool recursive
)
Summary
Deletes the specified directory and, if indicated, any subdirectories in the directory.
C# Syntax:
public static void Delete(
   string path,
   bool recursive
);
Parameters:

path

The fully qualified name of the directory to remove.

recursive

true to remove directories, subdirectories, and files in path; otherwise, false.

Exceptions
Exception Type Condition
IOException The directory specified by path is read-only, or recursive is false and path is not an empty directory.
SecurityException The caller does not have the required permission.
ArgumentException path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.InvalidPathChars.
ArgumentNullException path is null.
PathTooLongException The length of path or the absolute path information for path exceeds the system-defined maximum length.
DirectoryNotFoundException The specified path was not found.
Remarks
The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see Directory.GetCurrentDirectory.

The path parameter is not case-sensitive.

.NET Framework Security:
FileIOPermission for writing to the specified directory. Associated enumeration: FileIOPermissionAccess.Write

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Exists(
   string path
)
Summary
Determines whether the given path refers to an existing directory on disk.
C# Syntax:
public static bool Exists(
   string path
);
Parameters:

path

The path to test.

Return Value:
true if path refers to an existing directory; otherwise, false.
Remarks
The path argument is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory.

The path parameter is not case-sensitive.

Example
// For File.Exists, Directory.Exists
using System;
using System.IO;
using System.Collections;

 
// Takes an array of file names or directory names on the command line.  
// Determines what kind of name it is and processes it appropriately
public class RecursiveFileProcessor {
    public static void Main(string[] args) {
		foreach(string path in args) {
            if(File.Exists(path)) {
                // This path is a file
				ProcessFile(path); 
			}               
            else if(Directory.Exists(path)) {
                // This path is a directory
                ProcessDirectory(path);
            }
            else {
                Console.WriteLine("{0} is not a valid file or directory.", path);
            }        
        }        
    }


    // Process all files in the directory passed in, and recurse on any directories 
    // that are found to process the files they contain
    public static void ProcessDirectory(string targetDirectory) {
        // Process the list of files found in the directory
        string [] fileEntries = Directory.GetFiles(targetDirectory);
        foreach(string fileName in fileEntries)
    	    ProcessFile(fileName);

        // Recurse into subdirectories of this directory
        string [] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
		foreach(string subdirectory in subdirectoryEntries)
		    ProcessDirectory(subdirectory);
    }
        
    // Real logic for processing found files would go here.
	public static void ProcessFile(string path) {
        Console.WriteLine("Processed file '{0}'.", path);	    
	}
}

    
.NET Framework Security:
FileIOPermission for reading files. Associated enumeration: FileIOPermissionAccess.Read
See also:
DirectoryInfo

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~Directory();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetCreationTime(
   string path
)
Summary
Gets the creation date and time of a directory.
C# Syntax:
public static DateTime GetCreationTime(
   string path
);
Parameters:

path

The path of the directory.

Return Value:
A DateTime structure set to the creation date and time for the specified directory. This value is expressed in local time.
Exceptions
Exception Type Condition
IOException The directory specified by path is read-only or is not empty.
SecurityException The caller does not have the required permission.
ArgumentException path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.InvalidPathChars.
ArgumentNullException path is null.
PathTooLongException The length of path or the absolute path information for path exceeds the system-defined maximum length.
DirectoryNotFoundException The specified path was not found.
Remarks
GetCreationTime does not check whether the directory specified by path exists. This method is equivalent to File.GetCreationTime.

The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see Directory.GetCurrentDirectory.

The path parameter is not case-sensitive.

.NET Framework Security:
FileIOPermission for reading the specified file or directory. Associated enumeration: FileIOPermissionAccess.Read

Return to top


Method: GetCurrentDirectory()
Summary
Gets the current working directory of the application.
C# Syntax:
public static string GetCurrentDirectory();
Return Value:
A string containing the path of the current working directory.
Exceptions
Exception Type Condition
SecurityException The caller does not have the required permission.
Remarks
The current directory is distinct from the original directory, which is the one from which the process was started.
.NET Framework Security:
FileIOPermission for access to path information for the current directory. Associated enumeration: FileIOPermissionAccess.PathDiscovery

Return to top


Overloaded Method: GetDirectories(
   string path
)
Summary
Gets the names of subdirectories in the specified directory.
C# Syntax:
public static string[] GetDirectories(
   string path
);
Parameters:

path

The path for which an array of subdirectory names is returned.

Return Value:
An array of type String containing the names of subdirectories in path.
Exceptions
Exception Type Condition
SecurityException The caller does not have the required permission.
ArgumentException path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.InvalidPathChars.
ArgumentNullException path is null.
PathTooLongException The length of path or the absolute path information for path exceeds the system-defined maximum length.
DirectoryNotFoundException The specified path was not found.
Remarks
The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see Directory.GetCurrentDirectory.

This method is identical to GetDirectories.

The names returned by this method are prefixed with the directory information provided in path.

The path parameter is not case-sensitive.

Example
// For Directory.GetFiles and Directory.GetDirectories
// For File.Exists, Directory.Exists
using System;
using System.IO;
using System.Collections;

 
// Takes an array of file names or directory names on the command line.  
// Determines what kind of name it is and processes it appropriately
public class RecursiveFileProcessor {
    public static void Main(string[] args) {
		foreach(string path in args) {
            if(File.Exists(path)) {
                // This path is a file
				ProcessFile(path); 
			}               
            else if(Directory.Exists(path)) {
                // This path is a directory
                ProcessDirectory(path);
            }
            else {
                Console.WriteLine("{0} is not a valid file or directory.", path);
            }        
        }        
    }


    // Process all files in the directory passed in, and recurse on any directories 
    // that are found to process the files they contain
    public static void ProcessDirectory(string targetDirectory) {
        // Process the list of files found in the directory
        string [] fileEntries = Directory.GetFiles(targetDirectory);
        foreach(string fileName in fileEntries)
    	    ProcessFile(fileName);

        // Recurse into subdirectories of this directory
        string [] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
		foreach(string subdirectory in subdirectoryEntries)
		    ProcessDirectory(subdirectory);
    }
        
    // Real logic for processing found files would go here.
	public static void ProcessFile(string path) {
        Console.WriteLine("Processed file '{0}'.", path);	    
	}
}

    
.NET Framework Security:
FileIOPermission to access path information for the current directory. Associated enumeration: FileIOPermissionAccess.PathDiscovery

Return to top


Overloaded Method: GetDirectories(
   string path,
   string searchPattern
)
Summary
Gets an array of directories matching the specified search pattern from the current directory.
C# Syntax:
public static string[] GetDirectories(
   string path,
   string searchPattern
);
Parameters:

path

The path to search.

searchPattern

The search string to match against the names of files in path. The searchPattern parameter cannot contain Path.DirectorySeparatorChar or Path.AltDirectorySeparatorChar.

Return Value:
A String array of directories matching the search pattern.
Exceptions
Exception Type Condition
SecurityException The caller does not have the required permission.
ArgumentException path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.InvalidPathChars.

-or-

searchPattern does not contain a valid pattern.

ArgumentNullException path or searchPattern is null.
PathTooLongException The length of path or the absolute path information for path exceeds the system-defined maximum length.
DirectoryNotFoundException The specified path was not found.
Remarks
The following wildcard specifiers are permitted in searchPattern.

Wildcard character Description
* Zero or more characters.
? Exactly one character.

Characters other than the wildcard specifiers represent themselves. For example, the searchPattern string "*t" searches for all names in path ending with the letter "t". The searchPattern string "s*" searches for all names in path beginning with the letter "s".

The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see Directory.GetCurrentDirectory.

The path parameter is not case-sensitive.

.NET Framework Security:
FileIOPermission for access to path information for the current directory. Associated enumeration: FileIOPermissionAccess.PathDiscovery.

Return to top


Method: GetDirectoryRoot(
   string path
)
Summary
Returns the volume information, root information, or both for the specified path.
C# Syntax:
public static string GetDirectoryRoot(
   string path
);
Parameters:

path

The path of a file or directory.

Return Value:
A string containing the volume information, root information, or both for the specified path.
Exceptions
Exception Type Condition
SecurityException The caller does not have the required permission.
ArgumentException path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.InvalidPathChars.
ArgumentNullException path is null.
PathTooLongException The length of path or the absolute path information for path exceeds the system-defined maximum length.
Remarks
This method obtains the fully qualified path name of path, as returned by Path.GetFullPath, and returns root directory information. The specified path is not required to exist.

The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see Directory.GetCurrentDirectory.

The path parameter is not case-sensitive.

.NET Framework Security:
FileIOPermission for access to path information for the current directory. Associated enumeration: FileIOPermissionAccess.PathDiscovery

Return to top


Overloaded Method: GetFiles(
   string path
)
Summary
Returns the names of files in the specified directory.
C# Syntax:
public static string[] GetFiles(
   string path
);
Parameters:

path

The directory from which to retrieve the files.

Return Value:
A String array of file names in the specified directory.
Exceptions
Exception Type Condition
IOException The directory specified by path is read-only or is not empty.
SecurityException The caller does not have the required permission.
ArgumentException path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.InvalidPathChars.
ArgumentNullException path is null.
PathTooLongException The length of path or the absolute path information for path exceeds the system-defined maximum length.
DirectoryNotFoundException The specified path was not found.
Remarks
This method is identical to GetFiles.

The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see Directory.GetCurrentDirectory.

The path parameter is not case-sensitive.

Example
// For Directory.GetFiles and Directory.GetDirectories
// For File.Exists, Directory.Exists
using System;
using System.IO;
using System.Collections;

 
// Takes an array of file names or directory names on the command line.  
// Determines what kind of name it is and processes it appropriately
public class RecursiveFileProcessor {
    public static void Main(string[] args) {
		foreach(string path in args) {
            if(File.Exists(path)) {
                // This path is a file
				ProcessFile(path); 
			}               
            else if(Directory.Exists(path)) {
                // This path is a directory
                ProcessDirectory(path);
            }
            else {
                Console.WriteLine("{0} is not a valid file or directory.", path);
            }        
        }        
    }


    // Process all files in the directory passed in, and recurse on any directories 
    // that are found to process the files they contain
    public static void ProcessDirectory(string targetDirectory) {
        // Process the list of files found in the directory
        string [] fileEntries = Directory.GetFiles(targetDirectory);
        foreach(string fileName in fileEntries)
    	    ProcessFile(fileName);

        // Recurse into subdirectories of this directory
        string [] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
		foreach(string subdirectory in subdirectoryEntries)
		    ProcessDirectory(subdirectory);
    }
        
    // Real logic for processing found files would go here.
	public static void ProcessFile(string path) {
        Console.WriteLine("Processed file '{0}'.", path);	    
	}
}

    
.NET Framework Security:
FileIOPermission for access to path information for the current directory. Associated enumeration: FileIOPermissionAccess.PathDiscovery

Return to top


Overloaded Method: GetFiles(
   string path,
   string searchPattern
)
Summary
Returns the names of files in the specified directory that match the specified search pattern.
C# Syntax:
public static string[] GetFiles(
   string path,
   string searchPattern
);
Parameters:

path

The directory to search.

searchPattern

The search string to match against the names of files in path. The searchPattern parameter cannot contain Path.DirectorySeparatorChar or Path.AltDirectorySeparatorChar.

Return Value:
A String array containing the names of files in the specified directory that match the specified search pattern.
Exceptions
Exception Type Condition
IOException The directory specified by path is read-only or is not empty.
SecurityException The caller does not have the required permission.
ArgumentException path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.InvalidPathChars.

-or-

searchPattern does not contain a valid pattern.

ArgumentNullException path or searchPattern is null.
PathTooLongException The length of path or the absolute path information for path exceeds the system-defined maximum length.
DirectoryNotFoundException The specified path was not found.
Remarks
The following wildcard specifiers are permitted in searchPattern.

Wildcard character Description
* Zero or more characters.
? Exactly one character.

Characters other than the wild card specifiers represent themselves. For example, the searchPattern string "*t" searches for all names in path ending with the letter "t". The searchPattern string "s*" searches for all names in path beginning with the letter "s".

The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see Directory.GetCurrentDirectory.

The path paramenter is not case-sensitive.

.NET Framework Security:
FileIOPermission for access to path information for the current directory. Associated enumeration: FileIOPermissionAccess.PathDiscovery

Return to top


Overloaded Method: GetFileSystemEntries(
   string path
)
Summary
Returns the names of all files and subdirectories in the specified directory.
C# Syntax:
public static string[] GetFileSystemEntries(
   string path
);
Parameters:

path

The directory for which file and subdirectory names are returned.

Return Value:
A String array containing the names of file system entries in the specified directory.
Exceptions
Exception Type Condition
SecurityException The caller does not have the required permission.
ArgumentException path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.InvalidPathChars.
ArgumentNullException path is null.
PathTooLongException The length of path or the absolute path information for path exceeds the system-defined maximum length.
DirectoryNotFoundException The specified path was not found.

-or-

path is a file name.

Remarks
This method is identical to GetFileSystemEntries.

The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see Directory.GetCurrentDirectory.

The path parameter is not case-sensitive.

Example
using System;

namespace GetFileSystemEntries
{
	class Class1 {
		static void Main(string[] args) {
			Class1 snippets = new Class1();

			string path = System.IO.Directory.GetCurrentDirectory();
			string filter = "*.exe";

			snippets.PrintFileSystemEntries(path);
			snippets.PrintFileSystemEntries(path, filter);		
			snippets.GetLogicalDrives();
			snippets.GetParent(path);
			snippets.Move("C:\\proof", "C:\\Temp");
		}

		
		void PrintFileSystemEntries(string path) {
			
			try {
				// Obtain the file system entries in the directory path.
				string[] directoryEntries =
					System.IO.Directory.GetFileSystemEntries(path); 

				foreach (string str in directoryEntries) {
					System.Console.WriteLine(str);
				}
			}
			catch (ArgumentNullException) {
				System.Console.WriteLine("Path is a null reference.");
			}
			catch (System.Security.SecurityException) {
				System.Console.WriteLine("The caller does not have the " +
							"required permission.");
			}
			catch (ArgumentException) {
				System.Console.WriteLine("Path is an empty string, " +
							"contains only white spaces, " + 
							"or contains invalid characters.");
			}
			catch (System.IO.DirectoryNotFoundException) {
				System.Console.WriteLine("The path encapsulated in the " + 
							"Directory object does not exist.");
			}
		}
		void PrintFileSystemEntries(string path, string pattern) {
			try {
				// Obtain the file system entries in the directory
				// path that match the pattern.
				string[] directoryEntries =
					System.IO.Directory.GetFileSystemEntries(path, pattern); 

				foreach (string str in directoryEntries) {
					System.Console.WriteLine(str);
				}
			}
			catch (ArgumentNullException) {
				System.Console.WriteLine("Path is a null reference.");
			}
			catch (System.Security.SecurityException) {
				System.Console.WriteLine("The caller does not have the " +
							"required permission.");
			}
			catch (ArgumentException) {
				System.Console.WriteLine("Path is an empty string, " +
							"contains only white spaces, " + 
							"or contains invalid characters.");
			}
			catch (System.IO.DirectoryNotFoundException) {
				System.Console.WriteLine("The path encapsulated in the " + 
							"Directory object does not exist.");
			}
		}

		// Print out all logical drives on the system.
		void GetLogicalDrives() {
			try {
				string[] drives = System.IO.Directory.GetLogicalDrives();

				foreach (string str in drives) {
					System.Console.WriteLine(str);
				}
			}
			catch (System.IO.IOException) {
				System.Console.WriteLine("An I/O error occurs.");
			}
			catch (System.Security.SecurityException) {
				System.Console.WriteLine("The caller does not have the " +
							"required permission.");
			}
		}
		void GetParent(string path) {
			try {
				System.IO.DirectoryInfo directoryInfo =
					System.IO.Directory.GetParent(path);

				System.Console.WriteLine(directoryInfo.FullName);
			}
			catch (ArgumentNullException) {
				System.Console.WriteLine("Path is a null reference.");
			}
			catch (ArgumentException) {
				System.Console.WriteLine("Path is an empty string, " +
							"contains only white spaces, or " +
							"contains invalid characters.");
			}
		}
		void Move(string sourcePath, string destinationPath) {
			try {
				System.IO.Directory.Move(sourcePath, destinationPath);
				System.Console.WriteLine("The directory move is complete.");
			}
			catch (ArgumentNullException) {
				System.Console.WriteLine("Path is a null reference.");
			}
			catch (System.Security.SecurityException) {
				System.Console.WriteLine("The caller does not have the " +
							"required permission.");
			}
			catch (ArgumentException) {
				System.Console.WriteLine("Path is an empty string, " +
							"contains only white spaces, " + 
							"or contains invalid characters.");	
			}
			catch (System.IO.IOException) {
				System.Console.WriteLine("An attempt was made to move a " +
							"directory to a different " +
							"volume, or destDirName " +
							"already exists."); 
			}
		}
	}
}

    
.NET Framework Security:
FileIOPermission for access to path information for the current directory. Associated enumeration: FileIOPermissionAccess.PathDiscovery
See also:
FileSystemInfo

Return to top


Overloaded Method: GetFileSystemEntries(
   string path,
   string searchPattern
)
Summary
Returns an array of file system entries matching the specified search criteria.
C# Syntax:
public static string[] GetFileSystemEntries(
   string path,
   string searchPattern
);
Parameters:

path

The path to be searched.

searchPattern

The search string to match against the names of files in path. The searchPattern parameter cannot contain Path.DirectorySeparatorChar or Path.AltDirectorySeparatorChar.

Return Value:
A String array of file system entries matching the search criteria.
Exceptions
Exception Type Condition
SecurityException The caller does not have the required permission.
ArgumentException path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.InvalidPathChars.

-or-

searchPattern does not contain a valid pattern.

ArgumentNullException path or searchPattern is null.
PathTooLongException The length of path or the absolute path information for path exceeds the system-defined maximum length.
DirectoryNotFoundException The specified path was not found.

-or-

path is a file name.

Remarks
The following wildcard specifiers are permitted in searchPattern.

Wildcard character Description
* Zero or more characters.
? Exactly one character.

Characters other than the wild card specifiers represent themselves. For example, the searchPattern string "*t" searches for all names in path ending with the letter "t". The searchPattern string "s*" searches for all names in path beginning with the letter "s".

The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see Directory.GetCurrentDirectory.

The path parameter is not case-sensitive.

Example
using System;

namespace GetFileSystemEntries
{
	class Class1 {
		static void Main(string[] args) {
			Class1 snippets = new Class1();

			string path = System.IO.Directory.GetCurrentDirectory();
			string filter = "*.exe";

			snippets.PrintFileSystemEntries(path);
			snippets.PrintFileSystemEntries(path, filter);		
			snippets.GetLogicalDrives();
			snippets.GetParent(path);
			snippets.Move("C:\\proof", "C:\\Temp");
		}

		
		void PrintFileSystemEntries(string path) {
			
			try {
				// Obtain the file system entries in the directory path.
				string[] directoryEntries =
					System.IO.Directory.GetFileSystemEntries(path); 

				foreach (string str in directoryEntries) {
					System.Console.WriteLine(str);
				}
			}
			catch (ArgumentNullException) {
				System.Console.WriteLine("Path is a null reference.");
			}
			catch (System.Security.SecurityException) {
				System.Console.WriteLine("The caller does not have the " +
							"required permission.");
			}
			catch (ArgumentException) {
				System.Console.WriteLine("Path is an empty string, " +
							"contains only white spaces, " + 
							"or contains invalid characters.");
			}
			catch (System.IO.DirectoryNotFoundException) {
				System.Console.WriteLine("The path encapsulated in the " + 
							"Directory object does not exist.");
			}
		}
		void PrintFileSystemEntries(string path, string pattern) {
			try {
				// Obtain the file system entries in the directory
				// path that match the pattern.
				string[] directoryEntries =
					System.IO.Directory.GetFileSystemEntries(path, pattern); 

				foreach (string str in directoryEntries) {
					System.Console.WriteLine(str);
				}
			}
			catch (ArgumentNullException) {
				System.Console.WriteLine("Path is a null reference.");
			}
			catch (System.Security.SecurityException) {
				System.Console.WriteLine("The caller does not have the " +
							"required permission.");
			}
			catch (ArgumentException) {
				System.Console.WriteLine("Path is an empty string, " +
							"contains only white spaces, " + 
							"or contains invalid characters.");
			}
			catch (System.IO.DirectoryNotFoundException) {
				System.Console.WriteLine("The path encapsulated in the " + 
							"Directory object does not exist.");
			}
		}

		// Print out all logical drives on the system.
		void GetLogicalDrives() {
			try {
				string[] drives = System.IO.Directory.GetLogicalDrives();

				foreach (string str in drives) {
					System.Console.WriteLine(str);
				}
			}
			catch (System.IO.IOException) {
				System.Console.WriteLine("An I/O error occurs.");
			}
			catch (System.Security.SecurityException) {
				System.Console.WriteLine("The caller does not have the " +
							"required permission.");
			}
		}
		void GetParent(string path) {
			try {
				System.IO.DirectoryInfo directoryInfo =
					System.IO.Directory.GetParent(path);

				System.Console.WriteLine(directoryInfo.FullName);
			}
			catch (ArgumentNullException) {
				System.Console.WriteLine("Path is a null reference.");
			}
			catch (ArgumentException) {
				System.Console.WriteLine("Path is an empty string, " +
							"contains only white spaces, or " +
							"contains invalid characters.");
			}
		}
		void Move(string sourcePath, string destinationPath) {
			try {
				System.IO.Directory.Move(sourcePath, destinationPath);
				System.Console.WriteLine("The directory move is complete.");
			}
			catch (ArgumentNullException) {
				System.Console.WriteLine("Path is a null reference.");
			}
			catch (System.Security.SecurityException) {
				System.Console.WriteLine("The caller does not have the " +
							"required permission.");
			}
			catch (ArgumentException) {
				System.Console.WriteLine("Path is an empty string, " +
							"contains only white spaces, " + 
							"or contains invalid characters.");	
			}
			catch (System.IO.IOException) {
				System.Console.WriteLine("An attempt was made to move a " +
							"directory to a different " +
							"volume, or destDirName " +
							"already exists."); 
			}
		}
	}
}

    
.NET Framework Security:
FileIOPermission for access to path information for the current directory. Associated enumeration: FileIOPermissionAccess.PathDiscovery
See also:
FileSystemInfo

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetLastAccessTime(
   string path
)
Summary
Returns the date and time the specified file or directory was last accessed.
C# Syntax:
public static DateTime GetLastAccessTime(
   string path
);
Parameters:

path

The file or directory for which to obtain access date and time information.

Return Value:
A DateTime structure set to the date and time the specified file or directory was last accessed. This value is expressed in local time.
Exceptions
Exception Type Condition
IOException The specified path was not found.
SecurityException The caller does not have the required permission.
ArgumentException path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.InvalidPathChars.
ArgumentNullException path is null.
PathTooLongException The length of path or the absolute path information for path exceeds the system-defined maximum length.
Remarks
This method is identical to File.GetLastAccessTime.

GetLastAccessTime throws an IOException if the directory specified by path does not exist.

The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see Directory.GetCurrentDirectory.

The path parameter is not case-sensitive.

.NET Framework Security:
FileIOPermission for reading the specified file or directory. Associated enumeration: FileIOPermissionAccess.Read

Return to top


Method: GetLastWriteTime(
   string path
)
Summary
Returns the date and time the specified file or directory was last written to.
C# Syntax:
public static DateTime GetLastWriteTime(
   string path
);
Parameters:

path

The file or directory for which to obtain modification date and time information.

Return Value:
A DateTime structure set to the date and time the specified file or directory was last written to. This value is expressed in local time.
Exceptions
Exception Type Condition
IOException The specified path was not found.
SecurityException The caller does not have the required permission.
ArgumentException path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.InvalidPathChars.
ArgumentNullException path is null.
PathTooLongException The length of path or the absolute path information for path exceeds the system-defined maximum length.
Remarks
GetLastWriteTime does not check whether the directory specified by path exists.

The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see Directory.GetCurrentDirectory.

The path parameter is not case-sensitive.

.NET Framework Security:
FileIOPermission for reading the specified file or directory. Associated enumeration: FileIOPermissionAccess.Read

Return to top


Method: GetLogicalDrives()
Summary
Retrieves the names of the logical drives on this computer in the form "<drive letter>:\".
C# Syntax:
public static string[] GetLogicalDrives();
Return Value:
The logical drives on this computer.
Exceptions
Exception Type Condition
IOException An I/O error occurs (for example, a disk error).
SecurityException The caller does not have the required permission.
Example
using System;

namespace GetFileSystemEntries
{
	class Class1 {
		static void Main(string[] args) {
			Class1 snippets = new Class1();

			string path = System.IO.Directory.GetCurrentDirectory();
			string filter = "*.exe";

			snippets.PrintFileSystemEntries(path);
			snippets.PrintFileSystemEntries(path, filter);		
			snippets.GetLogicalDrives();
			snippets.GetParent(path);
			snippets.Move("C:\\proof", "C:\\Temp");
		}

		
		void PrintFileSystemEntries(string path) {
			
			try {
				// Obtain the file system entries in the directory path.
				string[] directoryEntries =
					System.IO.Directory.GetFileSystemEntries(path); 

				foreach (string str in directoryEntries) {
					System.Console.WriteLine(str);
				}
			}
			catch (ArgumentNullException) {
				System.Console.WriteLine("Path is a null reference.");
			}
			catch (System.Security.SecurityException) {
				System.Console.WriteLine("The caller does not have the " +
							"required permission.");
			}
			catch (ArgumentException) {
				System.Console.WriteLine("Path is an empty string, " +
							"contains only white spaces, " + 
							"or contains invalid characters.");
			}
			catch (System.IO.DirectoryNotFoundException) {
				System.Console.WriteLine("The path encapsulated in the " + 
							"Directory object does not exist.");
			}
		}
		void PrintFileSystemEntries(string path, string pattern) {
			try {
				// Obtain the file system entries in the directory
				// path that match the pattern.
				string[] directoryEntries =
					System.IO.Directory.GetFileSystemEntries(path, pattern); 

				foreach (string str in directoryEntries) {
					System.Console.WriteLine(str);
				}
			}
			catch (ArgumentNullException) {
				System.Console.WriteLine("Path is a null reference.");
			}
			catch (System.Security.SecurityException) {
				System.Console.WriteLine("The caller does not have the " +
							"required permission.");
			}
			catch (ArgumentException) {
				System.Console.WriteLine("Path is an empty string, " +
							"contains only white spaces, " + 
							"or contains invalid characters.");
			}
			catch (System.IO.DirectoryNotFoundException) {
				System.Console.WriteLine("The path encapsulated in the " + 
							"Directory object does not exist.");
			}
		}

		// Print out all logical drives on the system.
		void GetLogicalDrives() {
			try {
				string[] drives = System.IO.Directory.GetLogicalDrives();

				foreach (string str in drives) {
					System.Console.WriteLine(str);
				}
			}
			catch (System.IO.IOException) {
				System.Console.WriteLine("An I/O error occurs.");
			}
			catch (System.Security.SecurityException) {
				System.Console.WriteLine("The caller does not have the " +
							"required permission.");
			}
		}
		void GetParent(string path) {
			try {
				System.IO.DirectoryInfo directoryInfo =
					System.IO.Directory.GetParent(path);

				System.Console.WriteLine(directoryInfo.FullName);
			}
			catch (ArgumentNullException) {
				System.Console.WriteLine("Path is a null reference.");
			}
			catch (ArgumentException) {
				System.Console.WriteLine("Path is an empty string, " +
							"contains only white spaces, or " +
							"contains invalid characters.");
			}
		}
		void Move(string sourcePath, string destinationPath) {
			try {
				System.IO.Directory.Move(sourcePath, destinationPath);
				System.Console.WriteLine("The directory move is complete.");
			}
			catch (ArgumentNullException) {
				System.Console.WriteLine("Path is a null reference.");
			}
			catch (System.Security.SecurityException) {
				System.Console.WriteLine("The caller does not have the " +
							"required permission.");
			}
			catch (ArgumentException) {
				System.Console.WriteLine("Path is an empty string, " +
							"contains only white spaces, " + 
							"or contains invalid characters.");	
			}
			catch (System.IO.IOException) {
				System.Console.WriteLine("An attempt was made to move a " +
							"directory to a different " +
							"volume, or destDirName " +
							"already exists."); 
			}
		}
	}
}

    
.NET Framework Security:
SecurityPermission to call unmanaged code, such as calling native code with PInvoke or COM interop. Associated enumeration: SecurityPermissionFlag.UnmanagedCode

Return to top


Method: GetParent(
   string path
)
Summary
Retrieves the parent directory of the specified path, including both absolute and relative paths.
C# Syntax:
public static DirectoryInfo GetParent(
   string path
);
Parameters:

path

The fully qualified path for which to retrieve the parent directory.

Return Value:
The parent directory, or null if path is the root directory, including the root of a UNC server or share name.
Exceptions
Exception Type Condition
IOException The directory specified by path is read-only.
SecurityException The caller does not have the required permission.
ArgumentException path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.InvalidPathChars.
ArgumentNullException path is null.
PathTooLongException The length of path or the absolute path information for path exceeds the system-defined maximum length.
DirectoryNotFoundException The specified path was not found.
Remarks
The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see Directory.GetCurrentDirectory.

The path parameter is not case-sensitive.

Example
using System;

namespace GetFileSystemEntries
{
	class Class1 {
		static void Main(string[] args) {
			Class1 snippets = new Class1();

			string path = System.IO.Directory.GetCurrentDirectory();
			string filter = "*.exe";

			snippets.PrintFileSystemEntries(path);
			snippets.PrintFileSystemEntries(path, filter);		
			snippets.GetLogicalDrives();
			snippets.GetParent(path);
			snippets.Move("C:\\proof", "C:\\Temp");
		}

		
		void PrintFileSystemEntries(string path) {
			
			try {
				// Obtain the file system entries in the directory path.
				string[] directoryEntries =
					System.IO.Directory.GetFileSystemEntries(path); 

				foreach (string str in directoryEntries) {
					System.Console.WriteLine(str);
				}
			}
			catch (ArgumentNullException) {
				System.Console.WriteLine("Path is a null reference.");
			}
			catch (System.Security.SecurityException) {
				System.Console.WriteLine("The caller does not have the " +
							"required permission.");
			}
			catch (ArgumentException) {
				System.Console.WriteLine("Path is an empty string, " +
							"contains only white spaces, " + 
							"or contains invalid characters.");
			}
			catch (System.IO.DirectoryNotFoundException) {
				System.Console.WriteLine("The path encapsulated in the " + 
							"Directory object does not exist.");
			}
		}
		void PrintFileSystemEntries(string path, string pattern) {
			try {
				// Obtain the file system entries in the directory
				// path that match the pattern.
				string[] directoryEntries =
					System.IO.Directory.GetFileSystemEntries(path, pattern); 

				foreach (string str in directoryEntries) {
					System.Console.WriteLine(str);
				}
			}
			catch (ArgumentNullException) {
				System.Console.WriteLine("Path is a null reference.");
			}
			catch (System.Security.SecurityException) {
				System.Console.WriteLine("The caller does not have the " +
							"required permission.");
			}
			catch (ArgumentException) {
				System.Console.WriteLine("Path is an empty string, " +
							"contains only white spaces, " + 
							"or contains invalid characters.");
			}
			catch (System.IO.DirectoryNotFoundException) {
				System.Console.WriteLine("The path encapsulated in the " + 
							"Directory object does not exist.");
			}
		}

		// Print out all logical drives on the system.
		void GetLogicalDrives() {
			try {
				string[] drives = System.IO.Directory.GetLogicalDrives();

				foreach (string str in drives) {
					System.Console.WriteLine(str);
				}
			}
			catch (System.IO.IOException) {
				System.Console.WriteLine("An I/O error occurs.");
			}
			catch (System.Security.SecurityException) {
				System.Console.WriteLine("The caller does not have the " +
							"required permission.");
			}
		}
		void GetParent(string path) {
			try {
				System.IO.DirectoryInfo directoryInfo =
					System.IO.Directory.GetParent(path);

				System.Console.WriteLine(directoryInfo.FullName);
			}
			catch (ArgumentNullException) {
				System.Console.WriteLine("Path is a null reference.");
			}
			catch (ArgumentException) {
				System.Console.WriteLine("Path is an empty string, " +
							"contains only white spaces, or " +
							"contains invalid characters.");
			}
		}
		void Move(string sourcePath, string destinationPath) {
			try {
				System.IO.Directory.Move(sourcePath, destinationPath);
				System.Console.WriteLine("The directory move is complete.");
			}
			catch (ArgumentNullException) {
				System.Console.WriteLine("Path is a null reference.");
			}
			catch (System.Security.SecurityException) {
				System.Console.WriteLine("The caller does not have the " +
							"required permission.");
			}
			catch (ArgumentException) {
				System.Console.WriteLine("Path is an empty string, " +
							"contains only white spaces, " + 
							"or contains invalid characters.");	
			}
			catch (System.IO.IOException) {
				System.Console.WriteLine("An attempt was made to move a " +
							"directory to a different " +
							"volume, or destDirName " +
							"already exists."); 
			}
		}
	}
}

    
.NET Framework Security:
FileIOPermission for reading from files or directories. Associated enumeration: FileIOPermissionAccess.Read
See also:
DirectoryInfo

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Move(
   string sourceDirName,
   string destDirName
)
Summary
Moves a file or a directory and its contents to a new location.
C# Syntax:
public static void Move(
   string sourceDirName,
   string destDirName
);
Parameters:

sourceDirName

The path of the file or directory to move.

destDirName

The path to the new location for sourceDirName.

Exceptions
Exception Type Condition
IOException An attempt was made to move a directory to a different volume

-or-

destDirName already exists

-or-

The sourceDirName and destDirName parameters refer to the same file or directory.

SecurityException The caller does not have the required permission.
ArgumentException sourceDirName or destDirName is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.InvalidPathChars.
ArgumentNullException sourceDirName or destDirName is null.
PathTooLongException The length or absolute path information for sourceDirName or destDirName exceeds the system-defined maximum length.
DirectoryNotFoundException sourceDirName was not found.
Remarks
This method throws an IOException if, for example, you try to move c:\mydir to c:\public, and c:\public already exists. You must specify "c:\\public\\mydir" as the destDirName parameter, or specify a new directory name such as "c:\\newdir".

This method permits moving a directory to a read-only directory. The read/write attribute of neither directory is affected.

The sourceDirName and destDirName arguments are permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see Directory.GetCurrentDirectory.

Example
using System;

namespace GetFileSystemEntries
{
	class Class1 {
		static void Main(string[] args) {
			Class1 snippets = new Class1();

			string path = System.IO.Directory.GetCurrentDirectory();
			string filter = "*.exe";

			snippets.PrintFileSystemEntries(path);
			snippets.PrintFileSystemEntries(path, filter);		
			snippets.GetLogicalDrives();
			snippets.GetParent(path);
			snippets.Move("C:\\proof", "C:\\Temp");
		}

		
		void PrintFileSystemEntries(string path) {
			
			try {
				// Obtain the file system entries in the directory path.
				string[] directoryEntries =
					System.IO.Directory.GetFileSystemEntries(path); 

				foreach (string str in directoryEntries) {
					System.Console.WriteLine(str);
				}
			}
			catch (ArgumentNullException) {
				System.Console.WriteLine("Path is a null reference.");
			}
			catch (System.Security.SecurityException) {
				System.Console.WriteLine("The caller does not have the " +
							"required permission.");
			}
			catch (ArgumentException) {
				System.Console.WriteLine("Path is an empty string, " +
							"contains only white spaces, " + 
							"or contains invalid characters.");
			}
			catch (System.IO.DirectoryNotFoundException) {
				System.Console.WriteLine("The path encapsulated in the " + 
							"Directory object does not exist.");
			}
		}
		void PrintFileSystemEntries(string path, string pattern) {
			try {
				// Obtain the file system entries in the directory
				// path that match the pattern.
				string[] directoryEntries =
					System.IO.Directory.GetFileSystemEntries(path, pattern); 

				foreach (string str in directoryEntries) {
					System.Console.WriteLine(str);
				}
			}
			catch (ArgumentNullException) {
				System.Console.WriteLine("Path is a null reference.");
			}
			catch (System.Security.SecurityException) {
				System.Console.WriteLine("The caller does not have the " +
							"required permission.");
			}
			catch (ArgumentException) {
				System.Console.WriteLine("Path is an empty string, " +
							"contains only white spaces, " + 
							"or contains invalid characters.");
			}
			catch (System.IO.DirectoryNotFoundException) {
				System.Console.WriteLine("The path encapsulated in the " + 
							"Directory object does not exist.");
			}
		}

		// Print out all logical drives on the system.
		void GetLogicalDrives() {
			try {
				string[] drives = System.IO.Directory.GetLogicalDrives();

				foreach (string str in drives) {
					System.Console.WriteLine(str);
				}
			}
			catch (System.IO.IOException) {
				System.Console.WriteLine("An I/O error occurs.");
			}
			catch (System.Security.SecurityException) {
				System.Console.WriteLine("The caller does not have the " +
							"required permission.");
			}
		}
		void GetParent(string path) {
			try {
				System.IO.DirectoryInfo directoryInfo =
					System.IO.Directory.GetParent(path);

				System.Console.WriteLine(directoryInfo.FullName);
			}
			catch (ArgumentNullException) {
				System.Console.WriteLine("Path is a null reference.");
			}
			catch (ArgumentException) {
				System.Console.WriteLine("Path is an empty string, " +
							"contains only white spaces, or " +
							"contains invalid characters.");
			}
		}
		void Move(string sourcePath, string destinationPath) {
			try {
				System.IO.Directory.Move(sourcePath, destinationPath);
				System.Console.WriteLine("The directory move is complete.");
			}
			catch (ArgumentNullException) {
				System.Console.WriteLine("Path is a null reference.");
			}
			catch (System.Security.SecurityException) {
				System.Console.WriteLine("The caller does not have the " +
							"required permission.");
			}
			catch (ArgumentException) {
				System.Console.WriteLine("Path is an empty string, " +
							"contains only white spaces, " + 
							"or contains invalid characters.");	
			}
			catch (System.IO.IOException) {
				System.Console.WriteLine("An attempt was made to move a " +
							"directory to a different " +
							"volume, or destDirName " +
							"already exists."); 
			}
		}
	}
}

    
.NET Framework Security:
FileIOPermission for reading from sourceDirName and writing to sourceDirName or destDirName. Associated enumerations: FileIOPermissionAccess.Read, FileIOPermissionAccess.Write

Return to top


Method: SetCreationTime(
   string path,
   DateTime creationTime
)
Summary
Sets the creation date and time for the specified file or directory.
C# Syntax:
public static void SetCreationTime(
   string path,
   DateTime creationTime
);
Parameters:

path

The file or directory for which to set the creation date and time information.

creationTime

A DateTime containing the value to set for the creation date and time of path. This value is expressed in local time.

Exceptions
Exception Type Condition
IOException The specified path was not found.
ArgumentException path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.InvalidPathChars.
ArgumentNullException path is null.
PathTooLongException The length of path or the absolute path information for path exceeds the system-defined maximum length.
ArgumentOutOfRangeException creationTime specifies a value outside the range of dates or times permitted for this operation.
Remarks
The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see Directory.GetCurrentDirectory.

The path parameter is not case-sensitive.

.NET Framework Security:
FileIOPermission for writing to the specified file or directory. Associated enumeration: FileIOPermissionAccess.Write

Return to top


Method: SetCurrentDirectory(
   string path
)
Summary
Sets the application's current working directory to the specified directory.
C# Syntax:
public static void SetCurrentDirectory(
   string path
);
Parameters:

path

The path to which the current working directory is set.

Exceptions
Exception Type Condition
IOException The directory specified by path is read-only or is not empty.
ArgumentException path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.InvalidPathChars.
ArgumentNullException path is null.
PathTooLongException The length of path or the absolute path information for path exceeds the system-defined maximum length.
FileNotFoundException The specified path was not found.
Remarks
When the application terminates, the working directory is restored to its original location (the directory where the process was started).

The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see Directory.GetCurrentDirectory.

The path parameter is not case-sensitive.

.NET Framework Security:
FileIOPermission for writing to files or directories. Associated enumeration: FileIOPermissionAccess.Write

Return to top


Method: SetLastAccessTime(
   string path,
   DateTime lastAccessTime
)
Summary
Sets the date and time the specified file or directory was last accessed.
C# Syntax:
public static void SetLastAccessTime(
   string path,
   DateTime lastAccessTime
);
Parameters:

path

The file or directory for which to set the access date and time information.

lastAccessTime

A DateTime containing the value to set for the access date and time of path. This value is expressed in local time.

Exceptions
Exception Type Condition
IOException The specified path was not found.
ArgumentException path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.InvalidPathChars.
ArgumentNullException path is null.
PathTooLongException The length of path or the absolute path information for path exceeds the system-defined maximum length.
SecurityException The caller does not have the required permission.
Remarks
The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see Directory.GetCurrentDirectory.

The path parameter is not case-sensitive.

.NET Framework Security:
FileIOPermission for writing to the specified file or directory. Associated enumeration: FileIOPermissionAccess.Write

Return to top


Method: SetLastWriteTime(
   string path,
   DateTime lastWriteTime
)
Summary
Sets the date and time a directory was last written to.
C# Syntax:
public static void SetLastWriteTime(
   string path,
   DateTime lastWriteTime
);
Parameters:

path

The path of the directory.

lastWriteTime

The date and time the directory was last written to.

Exceptions
Exception Type Condition
IOException The specified path was not found.
ArgumentException path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.InvalidPathChars.
ArgumentNullException path is null.
PathTooLongException The length of path or the absolute path information for path exceeds the system-defined maximum length.
SecurityException The caller does not have the required permission.
Remarks
The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see Directory.GetCurrentDirectory.

The path parameter is not case-sensitive.

.NET Framework Security:
FileIOPermission for writing to the specified file or directory. Associated enumeration: FileIOPermissionAccess.Write

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.