/
DeleteWithoutNumbersProcessor.cs
52 lines (48 loc) · 1.52 KB
/
DeleteWithoutNumbersProcessor.cs
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Daramkun.DaramRenamer.Processors.Number
{
[Serializable]
public class DeleteWithoutNumbersProcessor : IProcessor
{
private static char [] spliters = new char [] {
' ', '[', ']', ',', '.', '(', ')', '{', '}', '<', '>', ' ',
'\t', ':', ';', '*', '&', '@', '^', '-', '_', '=', '+', '~',
};
public string Name => "process_delete_without_numbers";
public bool CannotMultithreadProcess => false;
[Localized ( "delwtnum_wordly" )]
public bool IsWordlyProcessing { get; set; } = false;
public bool Process ( FileInfo file )
{
if ( file.ChangedFilename.Length == 0 ) return false;
if ( !IsWordlyProcessing )
{
StringBuilder sb = new StringBuilder ();
foreach ( char ch in Path.GetFileNameWithoutExtension ( file.ChangedFilename ) )
if ( ch >= '0' && ch <= '9' )
sb.Append ( ch );
file.ChangedFilename = $"{ sb }{ Path.GetExtension ( file.ChangedFilename ) }";
}
else
{
List<string> split = new List<string> ( Path.GetFileNameWithoutExtension ( file.ChangedFilename ).Split ( spliters ) );
StringBuilder sb = new StringBuilder ();
foreach ( var str in split )
{
foreach ( var ch in str )
if ( ch >= '0' && ch <= '9' )
sb.Append ( ch );
sb.Append ( ' ' );
}
sb.Remove ( sb.Length - 1, 1 );
file.ChangedFilename = $"{ sb }{ Path.GetExtension ( file.ChangedFilename ) }";
}
return true;
}
}
}