paths, files, directories, I/O Common Operations Summary (ii)

Source: Internet
Author: User
Tags instance method

Summary:

File manipulation is a very basic and important part of the program, while paths, files, directories, and I/O are common themes in file operations, here's a summary of these common issues, and try to provide solutions to every problem, even without the answers you want, and hopefully provide you with some helpful ideas, If you have good suggestions, please be able to leave a message to make these content more perfect.

Main content:

The related operation of the path, such as determining whether the path is legitimate, the path type, the specific part of the path, the merged path, the system folder path and so on;

The related Common file dialog box, these dialog boxes can help us to operate the file system files and directories;

Iii. files, directories, drive operations, such as obtaining basic information about them, getting and setting properties of files and directories, file version information,

Search files and directories, file a sentence, copy, move, delete, rename files and directories;

Read and write files, including temporary files, random file names, etc.;

V. Monitoring of the file system;

The last article introduces the first to second part, which introduces the most important part of the third section.

Third, file and directory-related operations

The classes involved in file and directory operations are mainly: Fileinfo,directoryinfo,driveinfo, which can be thought to correspond to a single instance of a file, directory, and drive. They are similar in usage, typically by passing the path of a file, directory, or drive as a parameter to the appropriate constructor to create an instance, and then accessing their properties and methods.

Note the following points:

Both the FileInfo class and the DirectoryInfo class inherit from the abstract class FileSystemInfo, and the FileSystemInfo class defines some common properties, such as CreationTime, Exists, and so on. However, the DriveInfo class does not inherit the FileSystemInfo class, so it does not have the common properties mentioned above.

Objects of the FileInfo class and the DirectoryInfo class expose property values that are obtained when the first query is made, and they must be updated by calling their Refresh method if the file or directory changes after the query is taken. But DriveInfo does not need to do this, and its properties read the latest information about the file system every time.

When you create an instance of a file, directory, or drive, if you use a path that does not exist, and you do not make an error, you get an object that represents an entity that does not exist, which means that its Exists property (the IsReady attribute for DriveInfo) is false. You can still manipulate the entity, but if you try most of the other properties, it raises the corresponding FileNotFoundException, directorynotfoundexception, or Drivenotfoundexception exception.

In addition, you can also use the File/directory class, where members of these two classes are static methods, so if you want to perform only one operation, the efficiency of using static methods in File/directory is more efficient than using the corresponding fileinfo/directoryinfo in the Instance methods may be higher. All file/directory methods require the path of the file/directory that is currently being manipulated. Note: The static methods of the File/directory class perform security checks on all methods. If you plan to reuse an object multiple times, consider using the appropriate instance method for Fileinfo/directoryinfo, because security checks are not always required.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.