Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace FebTwoTwo
- {
- class Program
- {
- //set path, get files and order by file creation time
- public static string rootPath = @"C:\temp";
- public static DirectoryInfo info = new DirectoryInfo(rootPath);
- public static FileInfo[] files = info.GetFiles().OrderBy(p => p.CreationTime).ToArray();
- static void Main(string[] args)
- {
- #region
- if(files.Count() <= 3)
- {
- foreach (FileInfo file in files)
- {
- Console.WriteLine(file);
- }
- }
- else
- {
- int i = 0;
- for (i = 0; i <2; i++)
- {
- Console.WriteLine(files[i]);
- }
- Console.WriteLine("Plus {0} more files", files.Length - i);
- }
- #endregion
- Console.Read();
- //Change file names
- int counter = 1;
- foreach (FileInfo file in files)
- {
- string formatName = "My Files";
- string name = file.Name;
- string extension = file.Extension;
- string fullName = file.FullName;
- File.Move(file.FullName, file.FullName.Replace(file.Name, formatName + counter.ToString() + file.Extension));
- counter++;
- //File.Move takes the path of the original file (file.FullName) and moves it to the destination path (File.FullName.Replace)
- //Replace takes the old string (original path) and replaces it with a new path
- //Example it changes C:\temp\picture.jpeg to C:\temp\MyFile1.jpeg
- }
- Console.WriteLine("Files Renamed");
- Console.Read();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement