Skip to content

How i get list of files in a folder and create new files

jimson fernandez

Asked Apr 13, 2010, 10:55 PM EDT1 answer
Share
LinkedInX
windows c Sharp
In my project one folder name Root in

Root contains .txt files
eg: text.txt, text1.txt, text2.txt
how i can get list of all files and i am created new file using coding
how i name it automatically for file name text3.text
and how i read last created file in this directory

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Hirendra Sisodiya
    0
    hello jimson
    you can find list of all  textfile by this code:
    string Filenames="";
    DirectoryInfo Dir=new DirectoryInfo("C:\\trash");
    FileInfo[] files = Dir.GetFiles("*.txt");
    foreach (FileInfo tempfile in files)
    {
    Filenames = Filenames + " , " + tempfile.Name.ToString();
    DateTime dt = tempfile.CreationTime;
    }
    you can also find created time of each file so you can find latest created time....
     
    thanks
    Please mark as answere if it helps 
    0