Screedump form Windows PowerShell ISE

 

image

 

Code

$source = @"

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Rvl.Demo.Common
{
    public class MoveFiles
    {
        public static void Move()
        {
            string sourceFolder = @"C:\BDATA\Test\Source"; // Source folder
            string destinationFolder = @"C:\BDATA\Test\Destination"; // Destination folder
            DateTime checkDateTime = new DateTime(2010, 12, 29, 13, 0, 0); // 27-dec-2010 13:00:00
            // Loop all files in source folder
            foreach (string file in Directory.GetFiles(sourceFolder))
            {
                // Calculate difference between checkDateTime and file last modified datetime in days
                DateTime fileLastModifiedDate = File.GetLastWriteTime(file);

                // Move files if difference in days == 0
                if (checkDateTime.Year == fileLastModifiedDate.Year && checkDateTime.Month == fileLastModifiedDate.Month && checkDateTime.Day == fileLastModifiedDate.Day)
                {
                    string destinationFilePath = Path.Combine(destinationFolder, Path.GetFileName(file));
                    Console.WriteLine(string.Format("Moving file [{0}] to [{1}]", file, destinationFilePath));

                    File.Move(file, destinationFilePath);
                }
            }
        }
    }
}
"@

Add-Type -TypeDefinition $source

[Rvl.Demo.Common.MoveFiles]::Move()

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.