WindowsFileSystem:
DirectoryInfo Class:
The class provides numerous instance methods to move,
copy, create and enumerate through directories and sub directories.
Commonly used methods of directoryinfo class:
Create():
Is used
to create a directory at specified path.
DirectoryInfo dirinfo = new DirectoryInfo("D:\\New
Folder");
dirinfo.Create();
CreateSubdirectory():
Creates subdirectory or subdirectories for the specified path, which is an
instance of Directoryinfo class.
DirectoryInfo dirinfo = new DirectoryInfo("D:\\New
Folder");
dirinfo.CreateSubdirectory("New Folder");
Delete():
Is used to delete the directory.
dirinfo.Delete();
GetFiles():
Is used to get the list of all files in a
directory.
dirinfo.GetFiles
();
GetDirectories():
Is used to get the list of all directories
in a directory.
dirinfo.GetDirectories ();
Referesh():
Is used to referesh the directory.
dirinfo.Refresh()
MoveTo():
Is used to move directory to the current
path to the specified path.
dirinfo.MoveTo("D:\\New Folder3");
FileInfo Class:
FileInfo Class provides numerious instance
methods to work with the files. The following are some of the commonly used methods
to work with files.
Create():
Is used
to create a file at specified path and name.
fs.Create();
Delete():
Is used
to delete a file.
fs.Delete();
CopyTo():
Is used
to copy a file from one path to another.
fs.CopyTo("E:\\New Folder");
MoveTo():
Is used
to move a file to new path.
fs.MoveTo("E:\\New Folder");
Open():
Is used
to open a file by using specifed file enumerator. Enumerator is used to specify
the mode of the file.
fs.Open(FileMode.Open);
OpenRead():
Is used
to create a read only file stream, to read the files.
fs.OpenRead();
OpenWrite():
Is used
to create a write only file stream, to write the files.
fs.OpenWrite();
No comments:
Post a Comment