0

I am looking for a recursive function that scan a specific folder and send result in a text file.

I would like to list in a text file all files and folder with size, path, creation date, file version if existing but I have no idea on how to proceed.

I found some way to scan recursively but not to recover all needed information.

1
  • What have you tried? This is one of the simplest recursive methods you can write. Commented Jun 26, 2012 at 13:46

3 Answers 3

1

You can do the following,

    GetFileInfo(string dir)
{
 try
       {
           FileInfo info = null;
           foreach (string d in Directory.GetDirectories(sDir))
           {
               foreach (string file in Directory.GetFiles(d))
               {
                info =  new FileInfo(file);
                //get all information using info here
               }
               GetFileInfo(d);
           }
       }
       catch (System.Exception excpt)
       {
           Console.WriteLine(excpt.Message);
       }
}
Sign up to request clarification or add additional context in comments.

Comments

1

Use the System.IO.FileInfo object and System.IO.DirectoryInfo object....other than that, show us what you've tried.

Comments

0

You can list a folder using System.IO.DirectoryInfo and System.IO.FileInfo as ganders said.If you can list one folder's content the rest is simple recursion.The idea is while listing root directory if one item in the root directory is a directory call the same function on this directory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.