Skip to content

Instantly share code, notes, and snippets.

@JerryNixon
Created July 18, 2022 23:07
Show Gist options
  • Save JerryNixon/c76f4d7fd51a08c745bd64a373ab067a to your computer and use it in GitHub Desktop.
Save JerryNixon/c76f4d7fd51a08c745bd64a373ab067a to your computer and use it in GitHub Desktop.
CIS-230-01 Week 05 Assignment Demo
using System.IO;
var path = @"c:\dev";
Directory.Delete(path, true);
Directory.CreateDirectory(path);
var array = new[] { "a", "b", "c" };
for (double i = 0; i < 500; i = i + .35)
{
var dateTime = DateTime.Now.AddDays(i);
var dateText = dateTime.ToString("yyyyMMdd");
var fileName = Guid.NewGuid().ToString();
var filePath = @$"{path}\{fileName}.txt";
File.WriteAllText(filePath, dateText);
}
var files = Directory.GetFiles(path);
foreach (var filePath in files)
{
var text = File.ReadAllText(filePath);
var year = text[0..4];
var month = text[4..6];
var day = text[6..];
var dateText = $"{month}/{day}/{year}";
var date = DateTime.Parse(dateText);
var monthName = date.ToString("MMMM");
var directoryPath = @$"{path}\{year}\{month} - {monthName}";
Directory.CreateDirectory(directoryPath);
var fileName = Path.GetFileName(filePath);
var dayName = date.ToString("dddd");
var newFilePath = $@"{directoryPath}\{day} ({dayName}) - {fileName}";
File.Move(filePath, newFilePath, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment