




已阅读5页,还剩13页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
更改文件名软件源代码一、主界面:用到的控件:主界面“Form1”页面源码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;using System.Windows.Forms.Design;namespace Files public partial class Files : Form public Files() InitializeComponent(); private void btnFile_Click(object sender, EventArgs e) FolderDialog openFolder = new FolderDialog(); if (openFolder.DisplayDialog() = DialogResult.OK) txtselectPath.Text = openFolder.Path.ToString(); txtOutPath.Text = txtselectPath.Text; else txtselectPath.Text = 你没有选择目录; private void getAllDir(string path,string status,string newName) if (Directory.Exists(path) string fileList = Directory.GetFileSystemEntries(path); /this.listview1.BeginUpdate(); /数据更新,UI暂时挂起,直到EndUpdate绘制控件,可以有效避免闪烁并大大提高加载速度 foreach (string file in fileList) FileInfo fi = new FileInfo(file); if (Directory.Exists(file) getAllDir(file,status,newName); else ListViewItem lvi = new ListViewItem(); /lvi.Text =Path.GetFileName(file) ; /lvi.SubItems.Add(file); /lvi.SubItems.Add(newName); /lvi.SubItems.Add(status); /this.listview1.Items.Add(lvi); switch (uControl.StaSize) case 1: time(status, newName, file, fi, lvi); break; case 2: if(fi.Length=102400) time(status, newName, file, fi, lvi); break; case 3: if(fi.Length=(1024*1024*1024) time(status, newName, file, fi, lvi); break; case 5: if(uControl.ComBox=1) if(fi.Length=(uControl.num*1024*1024*1024) time(status, newName, file, fi, lvi); if(uControl.ComBox=2) if(fi.Length(uControl.num*1024*1024*1024) time(status, newName, file, fi, lvi); break; /this.listview1.EndUpdate(); /结束数据处理,UI界面一次性绘制。 private void time(string status, string newName, string file, FileInfo fi, ListViewItem lvi) switch (uControl.StaTime) case 1: lvi.Text = Path.GetFileName(file); lvi.SubItems.Add(file); lvi.SubItems.Add(newName); lvi.SubItems.Add(status); this.listview1.Items.Add(lvi); break; case 2: int year, month, day; year = int.Parse(DateTime.Now.Year.ToString(); month = int.Parse(DateTime.Now.Month.ToString(); day = int.Parse(DateTime.Now.Month.ToString(); if (day - 7 = 0) month -= 1; if (month = 0) year -= 1; month = 12; day = DateTime.DaysInMonth(year, month) - 7 + day; else day = DateTime.DaysInMonth(year, month) - 7 + day; DateTime dt = DateTime.Parse(year.ToString() + / + month.ToString() + / + day.ToString(); if (fi.CreationTime.Date = dt.Date) lvi.Text = Path.GetFileName(file); lvi.SubItems.Add(file); lvi.SubItems.Add(newName); lvi.SubItems.Add(status); this.listview1.Items.Add(lvi); break; case 3: int year, month, day; year = int.Parse(DateTime.Now.Year.ToString(); month = int.Parse(DateTime.Now.Month.ToString(); day = int.Parse(DateTime.Now.Month.ToString(); if (month - 1 = 0) year -= 1; month = 12; DateTime dt = DateTime.Parse(year.ToString() + / + month.ToString() + / + day.ToString(); if (fi.CreationTime.Date = dt.Date) lvi.Text = Path.GetFileName(file); lvi.SubItems.Add(file); lvi.SubItems.Add(newName); lvi.SubItems.Add(status); this.listview1.Items.Add(lvi); break; case 4: int year, month, day; year = int.Parse(DateTime.Now.Year.ToString(); month = int.Parse(DateTime.Now.Month.ToString(); day = int.Parse(DateTime.Now.Month.ToString(); year -= 1; DateTime dt = DateTime.Parse(year.ToString() + / + month.ToString() + / + day.ToString(); if (fi.CreationTime.Date = dt.Date) lvi.Text = Path.GetFileName(file); lvi.SubItems.Add(file); lvi.SubItems.Add(newName); lvi.SubItems.Add(status); this.listview1.Items.Add(lvi); break; case 5: if (fi.CreationTime.Date = uControl.TimeBegin.Date) lvi.Text = Path.GetFileName(file); lvi.SubItems.Add(file); lvi.SubItems.Add(newName); lvi.SubItems.Add(status); this.listview1.Items.Add(lvi); break; private void button4_Click(object sender, EventArgs e) a = ; for (int i = 0; i this.listview1.Items.Count; i+) this.listview1.Itemsi.SubItems2.Text =newFileName(i)+Path.GetExtension(listview1.Itemsi.SubItems1.Text); this.listview1.Itemsi.SubItems3.Text = 未修改; string a = ; public string newFileName(int i) string str=null; string temp = null; if (groupBox4.Enabled = true) if (rb3.Checked = true) temp = Path.GetFileNameWithoutExtension(listview1.Itemsi.SubItems0.Text); str += txtFileName.Text; for (int n3 = int.Parse(this.numfile.Value.ToString(); n3 temp.Length; n3+) str += tempn3.ToString(); if (rb5.Checked = true) temp = Path.GetFileNameWithoutExtension(listview1.Itemsi.SubItems0.Text); for (int n5 =0; n5 temp.Length-int.Parse(numericUpDown3.Value.ToString(); n5+) str += tempn5.ToString(); str += txtFileName.Text; if (rb4.Checked = true) temp =Path.GetFileNameWithoutExtension( listview1.Itemsi.SubItems0.Text); for (int n4 = 0; n4 int.Parse(numericUpDown2.Value.ToString(); n4+) str += tempn4.ToString(); str += txtFileName.Text; for (int n4 = int.Parse(numericUpDown1.Value.ToString(); n4 temp.Length; n4+) str += tempn4.ToString(); if (groupBox3.Enabled = true) if(rb1.Checked = true) temp += Path.GetFileNameWithoutExtension(listview1.Itemsi.SubItems0.Text); for (int n = int.Parse(this.numfile.Value.ToString(); n temp.Length; n+) if (tempn.ToString() = txtset.Text) str += i.ToString(); else str += tempn.ToString(); if (rb2.Checked = true) temp += Path.GetFileNameWithoutExtension(listview1.Itemsi.SubItems0.Text); for (int n = int.Parse(this.numfile.Value.ToString(); n temp.Length; n+) if (tempn.ToString() = txtset.Text) if (i % 26 = 0) for (int t = 0; t =0 ; i-) listview1.Itemsi + n.Remove(); private void radioButton2_CheckedChanged(object sender, EventArgs e) if (radioButton2.Checked = true) groupBox3.Enabled = true; groupBox4.Enabled = false; if (radioButton3.Checked = true) groupBox3.Enabled = false; groupBox4.Enabled = true; private void Files_Load(object sender, EventArgs e) radioButton2_CheckedChanged(sender,e); timer1.Start(); private void timer1_Tick(object sender, EventArgs e) this.toolStripStatusLabel1.Text =当前时间:+ DateTime.Now.ToString(yyyy年MM月dd日 hh时mm分); this.toolStripStatusLabel3.Text =当前文件数:+ this.listview1.Items.Count.ToString(); this.toolStripStatusLabel2.Margin = new Padding(this.Size.Width/4,0,0,0); this.toolStripStatusLabel3.Margin = new Padding(this.Size.Width /4, 0, 0, 0); private void OpenFolderAndSelectFile(String fileFullName) System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(Explorer.exe); psi.Arguments = /n, + fileFullName; System.Diagnostics.Process.Start(psi); private void button2_Click_1(object sender, EventArgs e) if (uControl.Visible = true) groupBox2.Visible = true; uControl.Visible = false; else groupBox2.Visible = false; uControl.Visible = true; private void btnReady_Click(object sender, EventArgs e) a = ; for (int i = 0; i this.listview1.Items.Count; i+) this.listview1.Itemsi.SubItems2.Text = newFileName(i) + Path.GetExtension(listview1.Itemsi.SubItems1.Text); this.listview1.Itemsi.SubItems3.Text = 未修改; private void btnOpenFilePath_Click(object sender, EventArgs e) OpenFolderAndSelectFile(txtOutPath.Text); private void button1_Click(object sender, EventArgs e) if (txtselectPath.Text = ) MessageBox.Show(请输入搜索路径); return; if (this.rbNew.Checked = true) this.listview1.Items.Clear(); getAllDir(txtselectPath.Text, , ); public class FolderDialog : FolderNameEditor FolderNameEditor.FolderBrowser fDialog = new System.Windows.Forms.Design.FolderNameEditor.FolderBrowser(); public FolderDialog() public DialogResult DisplayDialog() return DisplayDialog(请选择一个文件夹); public DialogResult DisplayDialog(string description) fDialog.Description = description; return fDialog.ShowDialog(); public string Path get return fDialog.DirectoryPath; FolderDialog() fDialog.Dispose(); 用户控件“UControl”界面:用户控件“UControl”源码 :using System;using System.Collections.Generic;using System.ComponentModel;using System.Drawing;using System.Data;using System.Linq;using System.Text;using System.Windows.Forms;namespace Files public partial class UControl : UserControl public UControl() InitializeComponent(); staSize = staTime = 1; private int staSize, staTime; public int StaTime get return staTime; public int StaSize getreturn staSize; public int num get return int.Parse(numericUpDown1.Value.ToString(); public int ComBox get return comboBox1.SelectedIndex; public DateTime TimeBegin get return dateTimePicker1.Value; public DateTime TimeEnd get return dateTimePicker2.Value; private void radioButton5_CheckedChanged(object sender, EventArgs e) staSize = 5; if (radioButton5.Checked = true) numericUpDown1.Enabled = comboBox1.Enabled = true; else numericUpDown1.Enabled = comboBox1.Enabled = false; private void radioButton10_CheckedChanged(object sender, EventArgs e) staTime = 5; if (radioButton10.Checked = true) dateTimePicker1.Enabled = dateTimePicker2.Enab
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 孕期离婚协议模板定制与婚姻财产分割指导合同
- 离婚房产归女方协议书:女方权益保障范本
- 离婚协议书范本:无子女双方协议书
- 石家庄市二手房买卖交易合同终止后权益保障协议
- 离婚协议6865I版:财产分割及债务处理细则
- 城市综合体物业管理与能源采购合同
- 食品企业生产信息保密及食品安全责任合同
- 班组级安全培训内容模板课件
- 小班教学水果课件
- 2025年病理生理学乳腺组织病理变化模拟考试卷答案及解析
- 不交社保劳动合同模板
- 2024年云南省中考数学试题(含答案)
- GB 14102.1-2024防火卷帘第1部分:通用技术条件
- 越野跑策划方案
- 《光学含沙量测量仪率定规范》
- 高考日语应用文写作失物招领寻物启事课件
- 产值计算方案
- 冬季抢工措施方案
- 运用PDCA循环降低急诊科医护人员职业暴露发生率
- 充电桩施工组织设计
- 静脉治疗护理技术操作标准2023
评论
0/150
提交评论