Summary of file directories and file operations in C#

One: file directory operation

File operations are always and inseparable from the folder directory. Before processing the file, let us first understand several operation methods of the file directory.

1: Out of nothing: Directory and DirectoryInfo  

Create, open, move or modify file directories.

The difference with OpenFileDialog is that it will not jump out of the directory option box.

The difference from Path is that Directory can be directly modified to create a directory, while path only modifies the path string.

Main usage: 

string[] path = Directory.GetFiles(string path); Get the file names (file directory and file name) under the specified directory, and record all file names under the path starting from 0. 

Directory.CreateDirectory(string path); Create a folder under the specified path Move, Delete


2: Follow the vine: Path

Note that path only modifies the path string, not the actual operation of the file. Operate on related files and path strings, read file names, add suffix names, merge suffix names, etc.


Main usage:

Path.GetDirectoryName(string path); Get directory information

 Path.GetFileName(string path); Get the file name and extension

Path.GetExtension(); get the file extension

 3: Straight to the point: OpenFileDialog() and FolderBrowseDialog()

1: It will jump out of the folder and select the specified file for operation, which is equivalent to the file directory is selected by itself, and there is no need to directly obtain the name, path and other operations of the selected file in our creation directory.


Two: file operations

1:File和FileInfo

open file or read file

           

  FileInfo[] Pictures = dir.GetFiles("*.jpeg");//Use an array to save all files opened from the specified address, read one by one with foreach

2: Filestream file stream operation

Convert all files into bit format, so whether it is pictures, documents, audio and other formats can be read, the ability to process data is very powerful.


FileStream[] filestream = new FileStream(string path,FileMode); has multiple overloads.



             

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324500632&siteId=291194637