-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
101 lines (93 loc) · 3.43 KB
/
Form1.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace FileRenamer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.listView.DragDrop += new System.Windows.Forms.DragEventHandler(this.listView_DragDrop);
this.listView.DragEnter += new System.Windows.Forms.DragEventHandler(this.listView_DragEnter);
}
private void Form1_Load(object sender, EventArgs e)
{
listView.View = View.Details; //컬럼형식으로 변경
listView.FullRowSelect = true; //Row 전체 선택
listView.Columns.Add("번호", 40);
listView.Columns.Add("원래 이름", 100); //컬럼추가
listView.Columns.Add("변경될 이름", 100);
listView.Columns.Add("파일 위치", 150);
}
private void listView_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.All;
else
e.Effect = DragDropEffects.None;
}
private void listView_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
string[] paths = (string[])e.Data.GetData(DataFormats.FileDrop, false);
listView.BeginUpdate();
int count = listView.Items.Count;
foreach (string path in paths)
{
// TODO: 폴더일 경우 continue
string fileName = Path.GetFileName(path);
ListViewItem lvi = new ListViewItem((++count).ToString());
lvi.SubItems.Add(fileName);
lvi.SubItems.Add(fileName);
lvi.SubItems.Add(Path.GetDirectoryName(path));
lvi.ImageIndex = 0;
listView.Items.Add(lvi);
}
listView.EndUpdate();
}
private void applyButton_Click(object sender, EventArgs e)
{
foreach (ListViewItem eachFile in listView.Items)
{
System.IO.File.Move(eachFile.SubItems[3].Text + "\\" + eachFile.SubItems[1].Text, eachFile.SubItems[3].Text + "\\" + eachFile.SubItems[2].Text);
}
}
/*
private string doProgress(string fileName)
{
string temp = fileName;
foreach (Tuple<string, string> pro in progressSave)
{
temp = temp.Replace(pro.Item1, pro.Item2);
}
return temp;
}*/
private void removeButton_Click(object sender, EventArgs e)
{
//foreach()
//listView.Items.RemoveAt();
foreach (ListViewItem eachItem in listView.SelectedItems)
{
listView.Items.Remove(eachItem);
}
for(int i = 0; i < listView.Items.Count; i++)
{
listView.Items[i].Text = (i + 1).ToString();
}
}
private void removeSpaceButton_Click(object sender, EventArgs e)
{
foreach (ListViewItem fileName in listView.Items)
{
fileName.SubItems[2].Text = fileName.SubItems[2].Text.Replace(" ", "");
}
}
}
}