-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
46 lines (41 loc) · 1.62 KB
/
Program.cs
File metadata and controls
46 lines (41 loc) · 1.62 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SortMp3
{
class Program
{
static void Main(string[] args)
{
var loOptions = new Options();
string lsFullFileName;
int lnCounter = 1;
if (CommandLine.Parser.Default.ParseArguments(args, loOptions))
{
if (!Directory.Exists(loOptions.OutputPath))
Directory.CreateDirectory(loOptions.OutputPath);
foreach (var loFileInfo in ReadMp3Files(loOptions.Mp3Path).OrderBy(item => item.CreationTime))
{
lsFullFileName = Path.Combine(loOptions.OutputPath, GetFileName(loFileInfo, lnCounter, loOptions));
if (File.Exists(lsFullFileName))
File.Delete(lsFullFileName);
File.Copy(loFileInfo.FullName, lsFullFileName);
lnCounter++;
}
}
}
private static List<FileInfo> ReadMp3Files(string psPath)
{
DirectoryInfo loDirectoryInfo = new DirectoryInfo(psPath);
return loDirectoryInfo.EnumerateFiles("*.mp3", SearchOption.AllDirectories).ToList();
}
private static string GetFileName(FileInfo poFileInfo, int pnCounter, Options poOptions)
{
string lsFormatString = "{0:" + poOptions.NumberFormat + "}_{1}";
return string.Format(lsFormatString, pnCounter, poFileInfo.Name);
}
}
}