예제 #1
0
        private void process(string source, FileToMove file)
        {
            var destination = transform(file, source);

            switch (file.Operation)
            {
            case FileOperation.Copy:
                this.Log.Write("Copying {0} to {1}.", source, destination);
                File.Copy(source, destination, true);
                break;

            case FileOperation.Delete:
                this.Log.Write("Deleting {0}.", source);
                File.Delete(source);
                break;

            case FileOperation.Move:
                this.Log.Write("Moving {0} to {1}.", source, destination);
                File.Move(source, destination);
                break;

            default:
                this.Log.Write(Severity.Warning, "Invalid Operation: {0}.", file.Operation);
                break;
            }
        }
예제 #2
0
        public static FileToMove Init(string source, string destination, FileOperation operation)
        {
            var f = new FileToMove();

            f.Source      = source;
            f.Destination = destination;
            f.Operation   = operation;
            return(f);
        }
예제 #3
0
        private void locate(FileToMove file)
        {
            var path    = Path.GetDirectoryName(file.Source);
            var pattern = Path.GetFileName(file.Source);
            var minDate = DateTime.Today;

            this.Log.Write(Severity.Debug, "Searching for {0} in {1} created after {2}.", pattern, path, minDate);

            var di   = new DirectoryInfo(path);
            var list = from f in di.GetFiles(pattern, SearchOption.TopDirectoryOnly)
                       where f.LastWriteTime.Date >= minDate
                       select f;

            if (list.Count() > 0)
            {
                foreach (FileInfo fi in list)
                {
                    this.Log.Write(Severity.Debug, "Found {0} created on {1}.", fi.Name, fi.LastWriteTime);
                    process(fi.FullName, file);
                }
            }
        }
예제 #4
0
        private string transform(FileToMove file, string source)
        {
            var output = file.Destination.Replace("*", Path.GetFileName(source));

            return(output);
        }