File and folder operations

Source: Internet
Author: User
Tags create directory

File and folder operations:

C/s:winform can manipulate client files
B/s:brower Server

Namespaces: Using System. IO;

1. File class:

Create: File.create (path); Create file, return FileStream

FileStream fs = file.create (path), after which it needs to be closed or not open, fs.close ();

Delete: File.delete (path); no return value

Copy files: file.copy (source file, target file);

Cut files: File.move (source file path, target path);

Determine if the file exists: file.exists (path); return Boolean, true means existing

File encryption: File.encrypt (); File.decrypt (); decrypt

File.getcreationtime (path); Get creation time, return datetime type Setcreationtime (path, datetime type); Modify creation time

File.getlastaccesstime (path); Last access time, return datetime type Setlastaccesstime (path, datetime type); Modify access time

File.getlastwritetime (path); Last modified time, return datetime type Setlastwritetime (path, datetime type); Modify modification Time


2. Directory classes, directories (folders)

Directory. CreateDirectory (path); Create directory

Directory. Delete (path); Remove directory

Directory. Exists (path), whether the directory exists

Three-time get and set

Directory. GetDirectories (path); Gets a subdirectory that returns a string array

Directory. GetFiles (path); Get Child Files! Name! , returns a string array, string[] s = Directory. GetFiles (path);

Directory. Getdirectoryroot (path); Get root directory

Directory. GetParent (path); Get Top level Directory

------------------------------------------------------------------------------------------------------

FileInfo class

Is the instance method, need to create object new to use, above is the static method of file

Create file: FileInfo f = new FileInfo (path); FileStream s = f.create (); S.close ();

Delete file: FileInfo f = new FileInfo (path); F.delete ();

Copy file: FileInfo f = new FileInfo (path), F.copyto (target path, whether overwrite (true is overwrite));

Move file: FileInfo f = new FileInfo (path); F.moveto (target path);

File exists: FileInfo f = new FileInfo (path); bool B = f.exists; Boolean, is a property

Get file name: FileInfo f = new FileInfo (path); string s = F.fullname; property, file name with path

Get creation time: DateTime d = f.creationtime, three time is the same, all attributes

Set creation time: F. CreationTime = DateTime.Now.AddDays (100); All three of them are the same.

Get file size: F. Length


DirectoryInfo class

Create directory: DirectoryInfo d = new DirectoryInfo (path); D.create ();

Delete directory: D. Delete ();

Move directory: D. MoveTo (target path);

Whether the directory exists: bool B = d.exists;

Get directory full name: D. FullName;

Get the Sub file! Object Information! : fileinfo[] f = d.getfiles (); Returns an array of file objects, the contents of which are more detailed, D.getfiles ("*.exe") only get EXE files

Get subdirectory: directoryinfo[] dr = D.getdirectories ();

File and folder operations

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.