Simple example of file manipulation in C #

Source: Internet
Author: User

Using system;using;namespace demo{class Program {static string tmppath = @ "D:/lgstest/diretorytes        T ";            static void Main (string[] args) {//createdirectory (Tmppath);            Ergodicdirectory (@ "d:\lgstest\c# practice \shenrulijiec#");        Console.readkey (); }//To determine if the specified path exists, and if it exists, it will be deleted and recreated, otherwise just create the static void CreateDirectory (string path) {//To determine if the given path is stored            In, note can only judge path (that is, folder), not specific to the file!!!                if (directory.exists (Tmppath)) {DirectoryInfo dic = new DirectoryInfo (Tmppath); Specify whether to delete subdirectories and files, if true, delete this directory, its subdirectories, and all files//If False, the directory is not empty will report an exception, that is, only when the directory is empty can be transmitted false dic.            Delete (TRUE);            } else {Console.WriteLine (false);        }//Create directory Directory.CreateDirectory (Tmppath); }//recursively traverse a directory to output the file name in its subdirectories static void Ergodicdirectory (string path) {IF (directory.exists (path)) {DirectoryInfo dir = new DirectoryInfo (path);                    if (null! = Dir) {//Returns an array of strongly typed System.IO.FileSystemInfo entries that represent all the files and subdirectories in a directory. filesysteminfo[] FileSystemInfo = dir.                    Getfilesysteminfos ();  for (int i = 0, Imax = filesysteminfo.length; i < IMAX; ++i) {FileSystemInfo                        Tmpfile = Filesysteminfo[i];                        Combined path String tmppath = Path.Combine (path,;                        if (Tmpfile is DirectoryInfo) {ergodicdirectory (Tmppath);                            } else {//output file name                        Console.WriteLine (;                   }}} or else { Console.WriteLine ("Wwwww");            }} else {Console.WriteLine ("QQQQ"); }        }    }}


Simple example of file manipulation in C #

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: 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.