|
-
July 25th, 2011, 12:34 PM
#1
Creating folder with timestamp in name
I'm creating a console application that moves files to an archive after a certain number of days. Within the archive folder, I want the application to create a folder that has a time stamp within the name i.e archive_20110725, so i can easily navigate to a certain days outputs. Here is my current code
using System;
using System.Configuration;
using System.IO;
namespace FileArchiver
{
class Program
{
static void Main(string[] args)
{
var pollingDirectory = ConfigurationManager.AppSettings["PollingDirectory"];
var archiverDirectory = ConfigurationManager.AppSettings["ArchiveDirectory"];
var fileRetention = Int32.Parse(ConfigurationManager.AppSettings["FileRetention"]);
foreach (var fullFileName in Directory.EnumerateFiles(pollingDirectory))
{
var fileInfo = new FileInfo(fullFileName);
var fileName = Path.GetFileName(fullFileName);
if(DateTime.Now.Subtract(new TimeSpan(fileRetention,0,0)) > fileInfo.CreationTime)
File.Move(fullFileName,Path.Combine(archiverDirectory,fileName));
}
}
}
}
Thanks for any advice,
Josh
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|