为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

定时备份文件夹

2017-12-11 6页 doc 30KB 15阅读

用户头像

is_142125

暂无简介

举报
定时备份文件夹定时备份文件夹 软件技术国家教学资源库建设项目 ——软件开发素材之C# 源代码 一、名称 定时备份文件夹 二、创建或搜集相关信息 搜集单位:重庆电子工程职业学院 搜集时间:2012-08-05 来 源:互联网 三、适用对象 学生、教师、C#及ASP.NET项目开发人员、相关技术人员等。 四、功能简介 实现定时备份文件夹功能。 五、程序代码 程序名称:Program.cs using System; using System.Collections.Generic; using System.Li...
定时备份文件夹
定时备份文件夹 软件技术国家教学资源库建设项目 ——软件开发素材之C# 源代码 一、名称 定时备份文件夹 二、创建或搜集相关信息 搜集单位:重庆电子职业学院 搜集时间:2012-08-05 来 源:互联网 三、适用对象 学生、教师、C#及ASP.NET项目开发人员、相关技术人员等。 四、功能简介 实现定时备份文件夹功能。 五、程序代码 程序名称:Program.cs using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace AutoBackup { static class Program { /// /// 应用程序的主入口点。 /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } } 程序名称:Form1.cs 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; namespace AutoBackup { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { dtTime.Value =Convert.ToDateTime(DateTime.Now.ToShortTimeString()); } private void btnSource_Click(object sender, EventArgs e) { FolderBrowserDialog folder = new FolderBrowserDialog(); if (folder.ShowDialog() == DialogResult.OK) { txtSource.Text = folder.SelectedPath; } } private void btnDest_Click(object sender, EventArgs e) { FolderBrowserDialog folder = new FolderBrowserDialog(); if (folder.ShowDialog() == DialogResult.OK) { txtDest.Text = folder.SelectedPath; } } private void timer1_Tick(object sender, EventArgs e) { if (DateTime.Now.ToShortTimeString() == dtTime.Value.ToShortTimeString()) { if (txtSource.Text != "" && txtDest.Text != "") { if (Directory.Exists(txtDest.Text + "\\" + DateTime.Now.Month.ToString()) == false) { Directory.CreateDirectory(txtDest.Text + "\\" + DateTime.Now.Month.ToString() + "月");//创建 月份文件夹 } CopyDirectory(txtSource.Text, txtDest.Text + "\\" + DateTime.Now.Month.ToString() + "\\" + DateTime.Now.Date.ToShortDateString()); } } } private void CopyDirectory(string sourcePath, string destPath) { DirectoryInfo dir = new DirectoryInfo(sourcePath);//实例化 FileSystemInfo[] fileinfo = dir.GetFileSystemInfos();//获取文件夹中所有目录 foreach (FileSystemInfo i in fileinfo) { if (i is DirectoryInfo)//判断是文件夹 { Directory.CreateDirectory(destPath + "\\" + i.Name);//创建文件夹 CopyDirectory(sourcePath + "\\" + i.Name, destPath + "\\" + i.Name);//递归调用 } else { if (File.Exists(destPath + "\\" + i.Name) == false)//文件 { File.Copy(i.FullName, destPath + "\\" + i.Name);//复制文件 } } } } } } 六、运行结果 图131 Program.cs运行结果
/
本文档为【定时备份文件夹】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索