原文发布时间为:2008-08-07 —— 来源于本人的百度文章 [由搬家工具导入]

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.IO;
using System.Text;

public partial class Default5 : System.Web.UI.Page
{
   
    private FileStream fs;
    private StreamWriter sw;
    private DirectoryInfo di;
    private FileInfo fi;
    protected void Page_Load(object sender, EventArgs e)
    {
       string fpath = Server.UrlDecode(Request.QueryString["url"]);
       string fname = Server.UrlDecode(Request.QueryString["fname"]);
       string ax = Server.UrlDecode(Request.QueryString["ax"]);
       Session["fpath"] = fpath;
       Session["lastfpath"] = Directory.GetParent(fpath).FullName;
        if (!IsPostBack)
        {         
            switch (ax)
            {
                case "editfile":
                    Panel1.Visible = true;
                    editfile(fpath, fname);
                    break;
                case "editdir":
                    Panel2.Visible = true;
                    editdir(fname);
                    break;
                case "deletedir":
                    Panel3.Visible = true;
                    deletedir(fname);
                    break;
                case "deletefile":
                    Panel4.Visible = true;
                    deletefile(fname);
                    break;              
                case "movefile":
                    Panel5.Visible = true;
                    movefile(fname,fpath);
                    break;
                case "movedir":
                    Panel6.Visible = true;
                    movedir(fname,fpath);
                    break;
                case "copyfile":
                    Panel7.Visible = true;
                    copyfile(fpath);
                    break;
                case "copydir":
                    Panel8.Visible = true;
                    copydir(fpath);
                    break;
            }
        }
    }
    protected void TextBox2_TextChanged(object sender, EventArgs e)
    {

    }

    protected void editfile(string fpath,string fname)
    {
        TextBox1.Text=fname;
        TextBox2.Text = File.ReadAllText(fpath, Encoding.Default);
    }

    protected void Button1_Click(object sender, EventArgs e)
    {

        fs = new FileStream(Session["fpath"].ToString(), FileMode.Create, FileAccess.Write);
        sw = new StreamWriter(fs, Encoding.Default);
        sw.WriteLine(TextBox2.Text);
        sw.Close();
        fs.Close();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default4.aspx?fpath="+Session["lastfpath"].ToString());
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        di = new DirectoryInfo(Session["fpath"].ToString());
        string newpath = Session["lastfpath"].ToString() + "\\" + TextBox3.Text;
        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;
    }
    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+";
        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+";
        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("));
    }

    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("));
    }
    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+");
                }            
                else
               {
                   fi.CopyTo(newpath+");
               }
            }
            else
            {
                DirectoryInfo child_di=(DirectoryInfo)fsi;
                string olddir=child_di.FullName;
                string dirname=child_di.FullName.Substring(child_di.FullName.LastIndexOf(");
                string newchildpath=Path.Combine(newpath,dirname);
                if(!Directory.Exists(olddir))
                    Directory.CreateDirectory(olddir);
                dirCopy(olddir,newchildpath);
            }

       }
    }
}

net8:简易的文件磁盘管理操作二(包括文件以及文件夹的编辑创建删除移动拷贝重命名等)的更多相关文章

  1. net8:简易的文件磁盘管理操作一(包括文件以及文件夹的编辑创建删除移动拷贝重命名等)

    原文发布时间为:2008-08-07 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration ...

  2. linux磁盘管理系列二:软RAID的实现

    磁盘管理系列 linux磁盘管理系列一:磁盘配额管理   http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_linux_040_quota.html l ...

  3. Linux常用命令之文件磁盘管理

    前言 本文知识点是曾经学习过程中收录整理的,方便学习使用. 一>Linux常用基本命令 Linux命令格式:command [-options] [parameter1] ... command ...

  4. media静态文件统一管理 操作内存的流 - StringIO | BytesIO PIL:python图片操作库 前端解析二进制流图片(了解) Admin自动化数据管理界面

    一.media ''' 1. 将用户上传的所有静态文件统一管理 -- settings.py -- MEDIA_ROOT = os.path.join(BASE_DIR, 'media') 2. 服务 ...

  5. iOS文件和文件夹的创建,删除,移动, 拷贝,是否存在及简单数据类型的读写

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launc ...

  6. Linux命令(二十四) 磁盘管理命令(二) mkfs,mount

    一.格式化文件系统 mkfs 当完成硬盘分区以后要进行硬盘的格式化,mkfs系列对应的命令用于将硬盘格式化为指定格式的文件系统.mkfs 本身并不执行建立文件系统的工作,而是去调用相关的程序来执行.例 ...

  7. python中常用的文件和目录操作(二)

    一. os模块概述 python os模块提供了非常丰富的方法用来处理文件和目录 二. 导入os模块: import os 三. 常用方法 1. os.name 输出字符串表示正在使用的平台,如果是w ...

  8. Linux学习笔记(十四)磁盘管理(二):格式化、挂载以及Swap分区

    一.格式化 第一种写法 mkfs.文件系统 [分区名称(设备文件路径)] 例如:对sdb硬盘的第一个分区以ext3文件系统进行格式化 第二种写法 mkfs -t 文件系统  [分区名称(设备文件路径) ...

  9. 《DotNet Web应用单文件部署系列》二、打包wwwroot文件夹

    在这篇文章中,你将学到web缓存规则,文件传输中用到的压缩格式,以及如何手写代码响应请求.最后还能学到快速打包wwwroot文件夹组件用法. 一.了解Response Header 当第一次加载程序时 ...

随机推荐

  1. C++类构造函数、析构函数运行机理

    http://blog.sina.com.cn/s/blog_6fd68d5f0100n60h.html 前言--构造函数.析构函数的简单理解:1)构造函数---对象被创建时候调用的函数:2)析构函数 ...

  2. 闭包和OC的block的本质

    “闭包” 一词来源于以下两者的结合:要执行的代码块(由于自由变量被包含在代码块中,这些自由变量以及它们引用的对象没有被释放)和为自由变量提供绑定的计算环境(作用域). http://blog.csdn ...

  3. vue 获取汉字的全拼、简拼、首拼

    1.封装公共方法,获取汉字的全拼.简拼.首拼 export const Pinyin = { _JMcode:{ "-":"", "—":& ...

  4. shell脚本,创建50个文件,删除50个文件。

    [root@localhost ~]# cat create50.sh #!/bin/bash #创建50个文件 ` do touch student$i done echo "创建50个文 ...

  5. 初涉「带权并查集」&&bzoj3376: [Usaco2004 Open]Cube Stacking 方块游戏

    算是挺基础的东西 Description     约翰和贝茜在玩一个方块游戏.编号为1到n的n(1≤n≤30000)个方块正放在地上.每个构成一个立方柱.    游戏开始后,约翰会给贝茜发出P(1≤P ...

  6. phpstorm设置方法头信息备注

    一.目标,如下图,希望在方法上增加如下头信息备注 二.设置live template: 三.增加方法头信息备注,如下所示: * created by ${USER} at ${DATE} ${TIME ...

  7. 蓝牙学习(3) Linux kernel部分Bluetooth HCI分析

    在上文,https://blog.csdn.net/feiwatson/article/details/81712933中主要理解了在Kernel中USB adapter是如何实现USB设备驱动,以及 ...

  8. Lex与Yacc学习(一)之环境配置篇

    Abstract 在开发程序的过程中经常会遇到文本解析的问题,例如:解析 C 语言源程序,编写 脚本引擎等等,解决这种文本解析的方法有很多,一种方法就是自己手动用 C 或者 C++直接编写解析程序,这 ...

  9. java 获取音频文件时长

    需要导入jar包:jave 1.0.2 jar 如果是maven项目,在pom.xml文件中添加: <dependency> <groupId>it.sauronsoftwar ...

  10. [转]构建Python+Selenium2自动化测试环境(一)

    很久没有了解自动化了,最近发现项目中沉淀了很多东西,回归测试效 率很低,所以必须要考虑构建自动化来提供各个环节的小效率.由于忙于需求以及产品的流程规范,现在对于测试技术方面的研究也相对少了很多.不过不 ...