Click here to Skip to main content
Licence CPOL
First Posted 26 Feb 2008
Views 11,676
Bookmarked 15 times

Getting File Info

By | 26 Feb 2008 | Article
Getting File Info from files in directory and subdirectories

Introduction

Get Information about when files were last updated in a directory.

Background

I was developing an ASP application where we worked on a TEST server first and then copied the files that contained the updated files to the LIVE server, I found myself forgetting on what files i had updated, so i decided to build an easy console app to show me what files that had been updated.

Using the code

	static string path = @"Z:\";

        static void Main(string[] args)
        {

            if (!Directory.Exists(path))
            {
                Console.WriteLine("The Directory doesnt exist, or it cant be accessed!");
                Console.ReadLine();
            }
            else
            {
               
                List<string> fl = Getfiles(path);
               
                foreach (string f in fl)
                {
                    
                    StreamWriter sw;
                    sw = File.AppendText(@"T:\Desktop\test.txt");
                    sw.WriteLine(f);
                    
                    sw.Close();
                    Console.WriteLine(f);
                }
            }

            Console.ReadLine();
        }		
   public static List<string> Getfiles(string path)
        {
            List<string> fileList = new List<string>();
            string[] subDirectories = Directory.GetDirectories(path);
            string[] files = Directory.GetFiles(path);

            foreach (string file in files)
            {
                DateTime dt = File.GetLastWriteTime(file);
                if (dt.ToShortDateString() == DateTime.Today.ToShortDateString())
                {
                    
                    fileList.Add(file + " " + dt);
                   
                }
            }
            foreach (string di in subDirectories)
            {
                string[] fi = Directory.GetFiles(di);
                foreach (string f in fi)
                {
                    DateTime dt = File.GetLastWriteTime(f);
                    if (dt.ToShortDateString() == DateTime.Today.ToShortDateString())
                    {
                        fileList.Add(f +" "+ dt);
                       
                    }
                }
            }

            return fileList;
        }

Points of Interest

This is my first article, so please be gentle :) Im sure theres alot of things you can do better than I have done. Feel free to comment on things that can be improved.

History

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Dreamzor



Sweden Sweden

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralUse the built-in types... PinmemberRay Hayes23:58 26 Feb '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 27 Feb 2008
Article Copyright 2008 by Dreamzor
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid