-
Notifications
You must be signed in to change notification settings - Fork 0
/
NameChanger.cs
64 lines (57 loc) · 1.97 KB
/
NameChanger.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
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using SharpShell.Attributes;
using SharpShell.SharpContextMenu;
namespace RandomNameChanger
{
[ComVisible(true)]
[COMServerAssociation(AssociationType.AllFiles)]
[COMServerAssociation(AssociationType.Directory)]
public class NameChanger : SharpContextMenu
{
protected override bool CanShowMenu()
{
return true;
}
protected override ContextMenuStrip CreateMenu()
{
// create the menu strip.
var menu = new ContextMenuStrip();
var RenameFileItem = new ToolStripMenuItem
{
Text = "Случайное имя",
Image = Properties.Resources.random
};
RenameFileItem.Click += (sender, args) => RenameFile();
menu.Items.Add(RenameFileItem);
return menu;
}
private void RenameFile()
{
foreach (var filePath in SelectedItemPaths)
{
string patchwitoutname = Path.GetDirectoryName(filePath);
string exten = Path.GetExtension(filePath);
string oldname = Path.GetFullPath(filePath);
string newname = patchwitoutname + "\\" + GeneratedName() + exten;
System.IO.Directory.Move(oldname, newname);
}
}
private static readonly Random rnd = new Random();
public string GeneratedName()
{
string parameters = "abcdefghijklnopqrstuvwxyz1234567890";
int count = 13;
string result = "";
// Random rnd = new Random();
int lenght = parameters.Length;
for (int i = 0; i < count; i++)
{
result += parameters[rnd.Next(lenght)];
}
return result;
}
}
}