Dark Horse programmer: knowledge about file operations

Source: Internet
Author: User

---------------------- ASP. NET + Android + I/O Development S,. Net training, hope to communicate with you! ----------------------
File Operation Knowledge
File // operation file, static class, overall operation on the file. Copy, delete, and cut.
Directory // operation directory (folder), static class.
Directoryinfo // a "class" of the folder to describe a folder object (A directoryinfo array is returned when all directories under the specified directory are obtained .)
Fileinfo // File class, used to describe a file object. Returns a fileinfo array when obtaining all objects in the specified directory.
Path // perform operations on the path of the file or directory (very convenient) [String]
Stream // file stream, abstract class.
Filestream // file stream, memorystream (memory stream), networkstream (Network Stream)
Streamreader // read text files quickly
Streamwriter // write text files quickly

Path class
Naming controls for directory and file operations: system. Io
String changeextension (string path, string extension)
Modify the suffix of a file. "modify" supports string-level operations and does not change the name of the file.
String S = path. changeextension (@ "C: \ temp \ f3.png", "jpg ")
String combine (string path1, string path2)
Combining Two paths into one path is better than using +, which can solve the problem of no diagonal lines and automatically process the path separator.
String S = path. Combine (@ "C: \ Temp", "a.jpg ")
String getdirectoryname (string path)
Obtain the path name of the file. Path. getdirectoryname (@ "C: \ temp \ a.jpg ")
String getextension (string path) to get the file extension
String getfilename (string path) to get the file name part of the file path
String getfilenamewithoutextension (string path) Get the file name with the removed Extension
String getfullpath (string path) to obtain the full path of the object. You can obtain the absolute path based on the relative path.
String gettempfilename () to get a unique temporary file name
String gettemppath () to obtain the path of the Temporary Folder
Path. Combine (path1, path2), see msdn
If one of the specified paths is a zero-length string, this method returns other paths. If path2 contains an absolute path, this method returns path2.
If path1 does not end with a separator and is not C: or D: (drive reference), add a \ separator for path1 before concatenation.
Separator: (related to the operating system platform)
Path. directoryseparatorchar → \
Path. pathseparator →;
Path. volumeseparatorchar →:
Path. getfilename ()
Get File Name
If the directory is c: \ windows \ test, you can obtain the name of the last directory. However, if the directory path is c: \ windows \ test \, no. View Reflector

Obtain the path for executing the current EXE file:
Assembly. getexecutingassembly (). location;
Application. startuppath.
Do not use:
Directory. getcurrentdirectory (); get the current working directory of the application. Because this may change, you can use openfiledialog or manually set directory. setcurrentdirectory ()

Directory and directoryinfo

Void Delete (string path, bool recursive) deletes a directory. Recursive indicates whether to recursively Delete the directory. If recursive is set to false, only empty directories can be deleted.
Bool exists (string path) determines whether the directory exists
String [] getdirectories (string path) to get a subdirectory under the Directory
String [] getdirectories (string path, string searchpattern, searchoption.
Static string [] getfiles (string path)
String [] getfiles (string path, string searchpattern, searchoption)
Directoryinfo getparent (string path) to get the parent directory of the Directory
Move () // move and cut. It can only be in the same disk. The directory does not have the copy method. You can use the move () method to rename a file.

Create ()

-------------------- ASP. NET + Android + iOS development,. Net training, and hope to communicate with you! ----------------------

See http://edu.csdn.net for details

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.