Skip to content

Instantly share code, notes, and snippets.

@TheDarkTrumpet
Last active December 14, 2017 16:45
Show Gist options
  • Select an option

  • Save TheDarkTrumpet/bc7a901e498e060103b0c7571a6d001c to your computer and use it in GitHub Desktop.

Select an option

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