|
-
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
-
July 25th, 2011, 12:36 PM
#2
Re: Creating folder with timestamp in name
-
July 25th, 2011, 01:16 PM
#3
Re: Creating folder with timestamp in name
-
July 26th, 2011, 07:13 AM
#4
Re: Creating folder with timestamp in name
string filename = String.Format("archive_{0:yyyyMMdd}", DateTime.Today);
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post. 
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
|