-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
144 lines (123 loc) · 4.62 KB
/
Form1.cs
File metadata and controls
144 lines (123 loc) · 4.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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 Microsoft.VisualBasic.FileIO;
using System.IO;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// 폴더 전체 복사 함수(하위폴더, 파일들 한번에)
public void CopyFolder(string sourceFolder, string targetFolder)
{
try
{
FileSystem.CopyDirectory(sourceFolder, targetFolder, UIOption.AllDialogs);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
//[.csv->.csv 파일 복사] 버튼 클릭하면 실행되는 함수
private void btn_csv_to_csv_Click(object sender, EventArgs e)
{
//
string str_source_Root;
string str_target_Root;
str_source_Root = this.textBox_source_csv.Text;
str_target_Root = this.textBox_target_CsvToCsv.Text;
CopyFolder(str_source_Root, str_target_Root);
MessageBox.Show("작업 완료");
}
// dir_path 폴더에 있는 txt 파일 csv로 변환해주는 함수
static void convert_txt_to_csv(string dir_path, string file_path)
{
string result = System.IO.Path.ChangeExtension(file_path, ".csv"); // "C:\Users\82109\Desktop\winform_test\CSVReader\source_csv\MS20N0016-17-1__20201202.csv"
System.IO.File.Move(file_path, result); //"C: \Users\82109\Desktop\winform_test\CSVReader\source_csv\MS20N0016 - 17 - 1__20201202.txt"
}
// root폴더부터 하위 폴더들 모두 돌면서 txt파일 찾는 함수
static void DirFileSearch(string dir_path, string extension)
{
try
{
//string str_file_path;
string[] dirs = Directory.GetDirectories(dir_path);
string[] files = Directory.GetFiles(dir_path, $"*.{extension}");
foreach (string str_file_path in files)
{
//str_file_path = f;
convert_txt_to_csv(dir_path, str_file_path);
}
if(dirs.Length > 0)
{
foreach (string dir in dirs)
{
DirFileSearch(dir, "txt");
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
//[.txt->.csv 변환 후 복사] 버튼 클릭하면 실행되는 함수
private void btn_txt_to_csv_Click(object sender, EventArgs e)
{
string str_source_Root;
string str_target_Root;
str_source_Root = this.textBox_source_txt.Text;
str_target_Root = this.textBox_target_TxtToCsv.Text;
// 복사 후 변환
CopyFolder(str_source_Root, str_target_Root);
DirFileSearch(str_target_Root, "txt");
MessageBox.Show("복사 완료");
}
//아래 4개 함수 모두 다 [폴더 열기] 버튼 관련 함수
private void folderOpenBnt_source_csv_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if(fbd.ShowDialog() == DialogResult.OK)
{
textBox_source_csv.Text = fbd.SelectedPath;
}
}
private void folderOpenBnt_target_csv_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
textBox_target_CsvToCsv.Text = fbd.SelectedPath;
}
}
private void folderOpenBnt_source_txt_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.SelectedPath = @"D:\source\";
fbd.ShowDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
textBox_source_txt.Text = fbd.SelectedPath;
}
}
private void folderOpenBnt_target_txt_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
textBox_target_TxtToCsv.Text = fbd.SelectedPath;
}
}
}
}