Last active
December 14, 2017 16:45
-
-
Save TheDarkTrumpet/bc7a901e498e060103b0c7571a6d001c to your computer and use it in GitHub Desktop.
Naive example of pulling from a directory and receiving all files, then determining information from them and sending to output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| string path = @"X:\Shared\OIT"; | |
| //Note: This is a very stupid way of doing this, but does work in our case. | |
| string[] allFiles = Directory.GetFiles(path, "*", SearchOption.AllDirectories); | |
| // Good for Debugging, but we're writing a simple CSV | |
| //Console.WriteLine("Total Number of Files: " + allFiles.Count()); | |
| //Start the header: | |
| Console.WriteLine("Directory,FileName,CreationTime,LastModified"); | |
| foreach (string file in allFiles) | |
| { | |
| string directoryName = Path.GetDirectoryName(file); | |
| string fileName = Path.GetFileName(file); | |
| DateTime createdDate = File.GetCreationTime(file); | |
| DateTime modifiedDate = File.GetLastWriteTime(file); | |
| //Output to console | |
| Console.WriteLine("\"{0}\",\"{1}\",{2},{3}", directoryName, fileName, createdDate.ToShortDateString(), modifiedDate.ToShortDateString()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment