选取路径 读取所需文件

FolderBrowserDialog sfd = new FolderBrowserDialog();
sfd.ShowDialog();

myTextbox1.Text = sfd.SelectedPath;

//查找文件 并 修改文件名称

string path = myTextbox1.Text;
DirectoryInfo theFolder = new DirectoryInfo(path);
DirectoryInfo[] dirInfo = theFolder.GetDirectories();
//遍历文件夹
foreach (FileInfo f in theFolder.GetFiles("*.MP4", SearchOption.TopDirectoryOnly)) //查找文件
{
//FileInfos info = new FileInfos();

string lastwritetime = f.LastWriteTime.ToString("yyyy-MM-dd HH-mm-ss");
string fullname = f.FullName;
if (!fullname.Contains('_'))
{
string[] Lfullname = fullname.Split('.');
string newpath = Lfullname[0] + "_" + lastwritetime + f.Extension;
if (comboBox2.Text != "")
{
newpath = Lfullname[0] + "_" + lastwritetime +"_" + comboBox2.Text + f.Extension;
}
if (System.IO.File.Exists(fullname))
{
System.IO.FileInfo file = new System.IO.FileInfo(fullname);

file.MoveTo(newpath);
}
}

}
this.Close();

 

posted @ 2017-11-09 15:44  demon丿  阅读(108)  评论(0编辑  收藏  举报