C\#실 현 된 파일 일괄 이름 바 꾸 기 기능 예제
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//C#
//
using System.IO;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog f1 = new FolderBrowserDialog();
if (f1.ShowDialog() == DialogResult.OK)
{
textBox3.Text = f1.SelectedPath;
}
}
private void button2_Click(object sender, EventArgs e)
{
if (textBox3.Text!=""){
if(textBox1.Text!="")
{
string strOldFileName;
string strNewFileName;
string strOldPart = this.textBox1.Text.Trim();
string strNewPart = this.textBox2.Text.Trim();
string strNewFilePath;
string strFileFolder;
int TotalFiles = 0;
DateTime StartTime = DateTime.Now;//
try{
DirectoryInfo di = new DirectoryInfo(textBox3.Text);
FileInfo[] filelist = di.GetFiles("*.*");
strFileFolder = textBox3.Text;
int i = 0;
foreach (FileInfo fi in filelist)
{
strOldFileName = fi.Name;
strNewFileName = fi.Name.Replace(strOldPart, strNewPart);
strNewFilePath = @strFileFolder + "\\" + strNewFileName;
filelist[i].MoveTo(@strNewFilePath);
TotalFiles += 1;
this.listBox1.Items.Add(" :" + strOldFileName + " " + strNewFileName + "");
i += 1;
}
DateTime EndTime = DateTime.Now;//
TimeSpan ts = EndTime - StartTime;
this.listBox1.Items.Add(" :" + ts.Hours.ToString() + " " + ts.Minutes.ToString() + " " + ts.Seconds.ToString() + " "+ ts.Milliseconds.ToString()+" ");
}
catch
{
MessageBox.Show(" !");
}
}
else
{
MessageBox.Show(" ");
}
}
else
{
MessageBox.Show(" !");
}
}
}
}
더 많은 C\#관련 내용 에 관심 이 있 는 독 자 는 본 사이트 의 주 제 를 볼 수 있다.본 고 에서 말 한 것 이 여러분 의 C\#프로 그래 밍 에 도움 이 되 기 를 바 랍 니 다.