C # File property read operations and file operations

Source: Internet
Author: User

C # get file last Modified date code
FileInfo f = new FileInfo (@ "C:\1.txt");
Console.WriteLine (F.lastwritetime.tostring ());
C # get file last access time code
FileInfo f = new FileInfo (@ "C:\1.txt");
Console.WriteLine (F.lastaccesstime.tostring ());//Last accessed
C # get file creation time code
FileInfo f = new FileInfo (@ "C:\1.txt");
Console.WriteLine (F.creationtime.tostring ());
C # get File size code
FileInfo f = new FileInfo (@ "C:\1.txt");
Console.WriteLine (F.length.tostring ());
C # Get File file Property code
FileInfo f = new FileInfo (@ "C:\1.txt");
Console.WriteLine (f.attributes);

C # File path

FileInfo f = new FileInfo (@ "C:\1.txt");
Console.WriteLine (F.directoryname);C # append file
StreamWriter SW = File.appendtext (Server.MapPath (".") + "\\myText.txt");
Sw. WriteLine ("Chasing the ideal");
Sw. WriteLine ("kzlll");
Sw. WriteLine (". NET Notes ");
Sw. Flush ();
Sw. Close ();
C # Copy files
String Orignfile,newfile;
Orignfile = Server.MapPath (".") + "\\myText.txt";
NewFile = Server.MapPath (".") + "\\myTextCopy.txt";
File.Copy (orignfile,newfile,true);
C # Delete Files
String delfile = Server.MapPath (".") + "\\myTextCopy.txt";
File.delete (Delfile);
C # moving files
String Orignfile,newfile;
Orignfile = Server.MapPath (".") + "\\myText.txt";
NewFile = Server.MapPath (".") + "\\myTextCopy.txt";
File.move (orignfile,newfile); To copy files from one directory to another
FileInfo fi = new FileInfo (path1);
Fi. CopyTo (path2, true);
path1 source file path, path2 destination file path.
Read (2423)| Comments (0)

C # File property read operations and file 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.