CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2011
    Posts
    4

    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

  2. #2
    Join Date
    Jul 2011
    Posts
    4

    Re: Creating folder with timestamp in name

    .NET4.0 / VS 2010 btw

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Creating folder with timestamp in name

    What's the problem?

  4. #4
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    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
  •  





Click Here to Expand Forum to Full Width

Featured