读书人

简易的资料磁盘管理操作1(文件、文件夹

发布时间: 2012-12-18 12:43:41 作者: rapoo

简易的文件磁盘管理操作1(文件、文件夹的编辑创建删除移动拷贝重命名)
??????? di.MoveTo(newpath);
??? }
??? protected void editdir(string fname)
??? {
??????? Label1.Text = fname;
??? }
??? protected void deletedir(string fname)
??? {
??????? Label2.Text = fname;
??? }
??? protected void deletefile(string fname)
??? {
??????? Label3.Text = fname;
??? }

//http://www.my400800.cn
??? protected void Button5_Click(object sender, EventArgs e)
??? {
??????? di = new DirectoryInfo(Session["fpath"].ToString());
??????? di.Delete();
??????? Response.Write("<script>alert('成功删除')</script>");
??????? Response.Redirect("Default4.aspx?fpath=" + Session["lastfpath"].ToString());
??? }
??? protected void Button7_Click(object sender, EventArgs e)
??? {
??????? fi = new FileInfo(Session["fpath"].ToString());
??????? fi.Delete();
??????? Response.Write("<script>alert('成功删除')</script>");
??????? Response.Redirect("Default4.aspx?fpath=" + Session["lastfpath"].ToString());
??? }
??? protected void movefile(string fname,string fpath)
??? {
??????? Label5.Text = fname;
??????? Label4.Text = Session["lastfpath"].ToString();
??????? TextBox4.Text = Session["lastfpath"].ToString();
??? }
??? protected void movedir(string fname, string fpath)
??? {
??????? Label6.Text = fname;
??????? Label7.Text = Session["lastfpath"].ToString();
??????? TextBox5.Text = Session["lastfpath"].ToString();
??? }
??? protected void Button9_Click(object sender, EventArgs e)
??? {
??????? fi = new FileInfo(Session["fpath"].ToString());
??????? string newfpath =TextBox4.Text+"\\"+Label5.Text;
??????? fi.MoveTo(newfpath);
??????? Response.Redirect("Default4.aspx?fpath=" +TextBox4.Text);
??? }
??? protected void Button11_Click(object sender, EventArgs e)
??? {
??????? di = new DirectoryInfo(Session["fpath"].ToString());
??????? string newfpath =TextBox5.Text+"\\"+Label6.Text;
??????? di.MoveTo(newfpath);
??????? Response.Redirect("Default4.aspx?fpath=" +TextBox5.Text);
??? }
??? protected void copyfile(string fpath)
??? {
??????? Label8.Text = fpath;
??????? TextBox6.Text = fpath;
??? }

??? protected void Button13_Click(object sender, EventArgs e)
??? {
??????? fi = new FileInfo(Label8.Text);
??????? fi.CopyTo(TextBox6.Text);
??????? Response.Redirect("Default4.aspx?fpath=" + TextBox6.Text.Substring(0,TextBox6.Text.LastIndexOf("\\")+1));
??? }

??? protected void copydir(string fpath)
??? {
??????? Label9.Text = fpath;
??????? TextBox7.Text = fpath;
??? }

??? protected void Button15_Click(object sender, EventArgs e)
??? {
???????? dirCopy(Label9.Text,TextBox7.Text);?????
???????? Response.Redirect("Default4.aspx?fpath="+TextBox7.Text.Substring(0,TextBox7.Text.LastIndexOf("\\")+1));
??? }
??? protected void dirCopy(string oldpath,string newpath)
??? {
???????? di = new DirectoryInfo(oldpath);
??????? foreach(FileSystemInfo fsi in di.GetFileSystemInfos())
??????? {
??????????? if(fsi is FileInfo)
??????????? {
??????????????? fi = (FileInfo)fsi;
??????????????? if(!Directory.Exists(newpath))
??????????????? {
?????????????????? DirectoryInfo newDir= Directory.CreateDirectory(newpath);
?????????????????? fi.CopyTo(newDir.FullName+"\\"+fi.Name);
??????????????? }????????????
??????????????? else
?????????????? {
?????????????????? fi.CopyTo(newpath+"\\"+fi.Name);
?????????????? }
??????????? }
??????????? else
??????????? {
??????????????? DirectoryInfo child_di=(DirectoryInfo)fsi;
??????????????? string olddir=child_di.FullName;
??????????????? string dirname=child_di.FullName.Substring(child_di.FullName.LastIndexOf("\\")+1);
??????????????? string newchildpath=Path.Combine(newpath,dirname);
??????????????? if(!Directory.Exists(olddir))
??????????????????? Directory.CreateDirectory(olddir);
??????????????? dirCopy(olddir,newchildpath);
??????????? }

?????? }
??? }
}

读书人网 >编程

热点推荐