-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
54 lines (42 loc) · 1.85 KB
/
Copy pathProgram.cs
File metadata and controls
54 lines (42 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.IO;
using System.Text.RegularExpressions;
namespace File_Deduper
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please enter the Current Location of the files:");
string filesCurrentLocation = Console.ReadLine();
Console.WriteLine();
Console.WriteLine("Please enter the Location you wish to move the duplicate files to:");
string filesMoveToLocation = Console.ReadLine();
Console.WriteLine();
//Check to see if the folders even exist.
if (!Directory.Exists(filesCurrentLocation))
throw new DirectoryNotFoundException("Current Location of Files Doesn't Exist");
if (!Directory.Exists(filesMoveToLocation))
throw new DirectoryNotFoundException("Move To Location of Files Doesn't Exist");
string[] filesToMove = Directory.GetFiles(filesCurrentLocation);
foreach (string filePath in filesToMove)
{
var nonCopyExists = false;
if (filePath.Contains("- Copy"))
{
if (Array.Exists(filesToMove, element => element == filePath.Replace(" - Copy", "")))
{
nonCopyExists = true;
}
}
string lastTenCharactersOfFile = filePath.Substring(filePath.Length - 10, 10);
var regex = new Regex(@"( - Copy )?(\(\d{1,3}\))(.mp3)$");
if (regex.IsMatch(lastTenCharactersOfFile) || nonCopyExists)
{
Console.WriteLine("Now Moving " + Path.GetFileName(filePath));
File.Move(filePath, filesMoveToLocation + @"\" + Path.GetFileName(filePath));
}
}
}
}
}