-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfix-double-ext.cs
More file actions
executable file
·58 lines (51 loc) · 1.8 KB
/
fix-double-ext.cs
File metadata and controls
executable file
·58 lines (51 loc) · 1.8 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
55
56
57
58
#!/usr/bin/csexec -r:R7.Scripting.dll
using System;
using System.IO;
using R7.Scripting;
public static class Program
{
public static int Main (string [] args) {
new FixDoubeExtScript ().Run ();
return 0;
}
}
public class FixDoubeExtScript
{
public void Run () {
var log = new Log ("fix-double-ext");
Directory.SetCurrentDirectory (Nautilus.CurrentDirectory);
try {
var files = Nautilus.SelectedFiles;
foreach (string file in files) {
try {
var ext1 = Path.GetExtension (file);
var fileName = Path.GetFileNameWithoutExtension (file);
var ext2 = Path.GetExtension (fileName);
if (!string.IsNullOrEmpty (ext2)) {
if (string.Compare (ext1, ext2, StringComparison.CurrentCultureIgnoreCase) == 0) {
var newFile = Path.Combine (
Path.GetDirectoryName (file),
Path.GetFileNameWithoutExtension (fileName)
) + ext1;
if (!File.Exists (newFile)) {
File.Move (file, newFile);
}
else {
log.WriteLine ("File already exists: " + newFile);
}
}
}
}
catch (Exception ex) {
log.WriteLine ("Error: " + ex.Message);
}
}
}
catch (Exception ex) {
log.WriteLine ("Error: " + ex.Message);
}
finally {
log.Close ();
}
}
}