<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 303  文章 - 883  trackbacks - 0
    <2007年3月>
    25262728123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    歡迎光臨! 
    閑聊 QQ:1074961813

    隨筆分類(357)

    我管理的群

    公共blog

    • n維空間
    • Email : java3d@126.com 群 : 12999758

    參與管理的論壇

    好友的blog

    我的其他blog

    朋友的網(wǎng)站

    搜索

    •  

    最新評(píng)論

    from? http://empolder.blog.sohu.com/32035968.html

    C#追加文件?
    StreamWriter?sw?
    =?File.AppendText(Server.MapPath(".")+"//myText.txt");?
    sw.WriteLine(
    "追逐理想");?
    sw.WriteLine(
    "kzlll");?
    sw.WriteLine(
    ".NET筆記");?
    sw.Flush();?
    sw.Close();?

    C#拷貝文件?
    string?OrignFile,NewFile;?
    OrignFile?
    =?Server.MapPath(".")+"//myText.txt";?
    NewFile?
    =?Server.MapPath(".")+"//myTextCopy.txt";?
    File.Copy(OrignFile,NewFile,
    true);?

    C#刪除文件?
    string?delFile?=?Server.MapPath(".")+"//myTextCopy.txt";?
    File.Delete(delFile);?

    C#移動(dòng)文件?
    string?OrignFile,NewFile;?
    OrignFile?
    =?Server.MapPath(".")+"//myText.txt";?
    NewFile?
    =?Server.MapPath(".")+"//myTextCopy.txt";?
    File.Move(OrignFile,NewFile);?

    C#創(chuàng)建目錄?
    //?創(chuàng)建目錄c:/sixAge?
    DirectoryInfo?d=Directory.CreateDirectory("c://sixAge");?
    //?d1指向c:/sixAge/sixAge1?
    DirectoryInfo?d1=d.CreateSubdirectory("sixAge1");?
    //?d2指向c:/sixAge/sixAge1/sixAge1_1?
    DirectoryInfo?d2=d1.CreateSubdirectory("sixAge1_1");?
    //?將當(dāng)前目錄設(shè)為c:/sixAge?
    Directory.SetCurrentDirectory("c://sixAge");?
    //?創(chuàng)建目錄c:/sixAge/sixAge2?
    Directory.CreateDirectory("sixAge2");?
    //?創(chuàng)建目錄c:/sixAge/sixAge2/sixAge2_1?
    Directory.CreateDirectory("sixAge2//sixAge2_1");?

    遞歸刪除文件夾及文件?
    <%@?Page?Language=C#%>?
    <%@?Import?namespace="System.IO"%>?
    <Script?runat=server>?
    public?void?DeleteFolder(string?dir)?
    {?
    ????
    if?(Directory.Exists(dir))?//如果存在這個(gè)文件夾刪除之?
    ????{?
    ????????
    foreach(string?d?in?Directory.GetFileSystemEntries(dir))?
    ????????
    {?
    ????????????
    if(File.Exists(d))?
    ????????????????File.Delete(d);?
    //直接刪除其中的文件?
    ????????????else?
    ????????????????DeleteFolder(d);?
    //遞歸刪除子文件夾?
    ????????}
    ?
    ????????Directory.Delete(dir);?
    //刪除已空文件夾?
    ????????Response.Write(dir+"?文件夾刪除成功");?
    ????}
    ?
    ????
    else?
    ????????Response.Write(dir
    +"?該文件夾不存在");?//如果文件夾不存在則提示?
    }
    ?

    protected?void?Page_Load?(Object?sender?,EventArgs?e)?
    {?
    ????
    string?Dir="D://gbook//11";?
    ????DeleteFolder(Dir);?
    //調(diào)用函數(shù)刪除文件夾?
    }
    ?

    ?
    //?======================================================
    ??
    //?實(shí)現(xiàn)一個(gè)靜態(tài)方法將指定文件夾下面的所有內(nèi)容copy到目標(biāo)文件夾下面
    ??
    //?如果目標(biāo)文件夾為只讀屬性就會(huì)報(bào)錯(cuò)。
    ??
    //?April?18April2005?In?STU
    ??
    //?======================================================
    ??public?static?void?CopyDir(string?srcPath,string?aimPath)
    ??
    {
    ???
    try
    ???
    {
    ????
    //?檢查目標(biāo)目錄是否以目錄分割字符結(jié)束如果不是則添加之
    ????if(aimPath[aimPath.Length-1]?!=?Path.DirectorySeparatorChar)?
    ?????aimPath?
    +=?Path.DirectorySeparatorChar;
    ????
    //?判斷目標(biāo)目錄是否存在如果不存在則新建之
    ????if(!Directory.Exists(aimPath))?Directory.CreateDirectory(aimPath);
    ????
    //?得到源目錄的文件列表,該里面是包含文件以及目錄路徑的一個(gè)數(shù)組
    ????
    //?如果你指向copy目標(biāo)文件下面的文件而不包含目錄請(qǐng)使用下面的方法
    ????
    //?string[]?fileList?=?Directory.GetFiles(srcPath);
    ????string[]?fileList?=?Directory.GetFileSystemEntries(srcPath);
    ????
    //?遍歷所有的文件和目錄
    ????foreach(string?file?in?fileList)
    ????
    {
    ?????
    //?先當(dāng)作目錄處理如果存在這個(gè)目錄就遞歸Copy該目錄下面的文件
    ?????if(Directory.Exists(file))
    ??????CopyDir(file,aimPath
    +Path.GetFileName(file));
    ??????
    //?否則直接Copy文件
    ?????else
    ??????File.Copy(file,aimPath
    +Path.GetFileName(file),true);
    ????}

    ???}

    ???
    catch?(Exception?e)
    ???
    {
    ????MessageBox.Show?(e.ToString());
    ???}

    ??}
    ?

    ??
    //?======================================================
    ??
    //?實(shí)現(xiàn)一個(gè)靜態(tài)方法將指定文件夾下面的所有內(nèi)容Detele
    ??
    //?測(cè)試的時(shí)候要小心操作,刪除之后無法恢復(fù)。
    ??
    //?April?18April2005?In?STU
    ??
    //?======================================================
    ??public?static?void?DeleteDir(string?aimPath)
    ??
    {
    ???
    try
    ???
    {
    ????
    //?檢查目標(biāo)目錄是否以目錄分割字符結(jié)束如果不是則添加之
    ????if(aimPath[aimPath.Length-1]?!=?Path.DirectorySeparatorChar)?
    ?????aimPath?
    +=?Path.DirectorySeparatorChar;
    ????
    //?得到源目錄的文件列表,該里面是包含文件以及目錄路徑的一個(gè)數(shù)組
    ????
    //?如果你指向Delete目標(biāo)文件下面的文件而不包含目錄請(qǐng)使用下面的方法
    ????
    //?string[]?fileList?=?Directory.GetFiles(aimPath);
    ????string[]?fileList?=?Directory.GetFileSystemEntries(aimPath);
    ????
    //?遍歷所有的文件和目錄
    ????foreach(string?file?in?fileList)
    ????
    {
    ?????
    //?先當(dāng)作目錄處理如果存在這個(gè)目錄就遞歸Delete該目錄下面的文件
    ?????if(Directory.Exists(file))
    ?????
    {
    ??????DeleteDir(aimPath
    +Path.GetFileName(file));
    ?????}

    ??????
    //?否則直接Delete文件
    ?????else
    ?????
    {
    ??????File.Delete?(aimPath
    +Path.GetFileName(file));
    ?????}

    ????}

    ????
    //刪除文件夾
    ????System.IO?.Directory?.Delete?(aimPath,true);
    ???}

    ???
    catch?(Exception?e)
    ???
    {
    ????MessageBox.Show?(e.ToString());
    ???}

    ??}

    ?

    ?

    需要引用命名空間:
    using?System.IO;

    /**////?<summary>
    ??
    ///?拷貝文件夾(包括子文件夾)到指定文件夾下,源文件夾和目標(biāo)文件夾均需絕對(duì)路徑.?格式:?CopyFolder(源文件夾,目標(biāo)文件夾);
    ??
    ///?</summary>
    ??
    ///?<param?name="strFromPath"></param>
    ??
    ///?<param?name="strToPath"></param>


    ??
    //--------------------------------------------------
    ??
    //作者:明天去要飯??QQ:305725744
    ?
    //---------------------------------------------------

    ??
    public?static?void?CopyFolder(string?strFromPath,string?strToPath)
    ??
    {
    ???
    //如果源文件夾不存在,則創(chuàng)建
    ???if?(!Directory.Exists(strFromPath))
    ???
    {????
    ????Directory.CreateDirectory(strFromPath);
    ???}
    ???

    ???
    //取得要拷貝的文件夾名
    ???string?strFolderName?=?strFromPath.Substring(strFromPath.LastIndexOf("//")?+?1,strFromPath.Length?-?strFromPath.LastIndexOf("//")?-?1);???

    ???
    //如果目標(biāo)文件夾中沒有源文件夾則在目標(biāo)文件夾中創(chuàng)建源文件夾
    ???if?(!Directory.Exists(strToPath?+?"//"?+?strFolderName))
    ???
    {????
    ????Directory.CreateDirectory(strToPath?
    +?"//"?+?strFolderName);
    ???}

    ???
    //創(chuàng)建數(shù)組保存源文件夾下的文件名
    ???string[]?strFiles?=?Directory.GetFiles(strFromPath);

    ???
    //循環(huán)拷貝文件
    ???for(int?i?=?0;i?<?strFiles.Length;i++)
    ???
    {
    ????
    //取得拷貝的文件名,只取文件名,地址截掉。
    ????string?strFileName?=?strFiles[i].Substring(strFiles[i].LastIndexOf("//")?+?1,strFiles[i].Length?-?strFiles[i].LastIndexOf("//")?-?1);
    ????
    //開始拷貝文件,true表示覆蓋同名文件
    ????File.Copy(strFiles[i],strToPath?+?"//"?+?strFolderName?+?"//"?+?strFileName,true);
    ???}

    ??
    ???
    //創(chuàng)建DirectoryInfo實(shí)例
    ???DirectoryInfo?dirInfo?=?new?DirectoryInfo(strFromPath);
    ???
    //取得源文件夾下的所有子文件夾名稱
    ???DirectoryInfo[]?ZiPath?=?dirInfo.GetDirectories();
    ???
    for?(int?j?=?0;j?<?ZiPath.Length;j++)
    ???
    {
    ????
    //獲取所有子文件夾名
    ????string?strZiPath?=?strFromPath?+?"//"?+?ZiPath[j].ToString();???
    ????
    //把得到的子文件夾當(dāng)成新的源文件夾,從頭開始新一輪的拷貝
    ????CopyFolder(strZiPath,strToPath?+?"//"?+?strFolderName);
    ???}

    ??}




    地震讓大伙知道:居安思危,才是生存之道。
    posted on 2007-03-28 16:26 小尋 閱讀(417) 評(píng)論(0)  編輯  收藏 所屬分類: c/c++/C#/pasic/vb/php/asp(.net)/win-cgi/xml...
    主站蜘蛛池模板: 精品多毛少妇人妻AV免费久久| 亚洲AV日韩AV一区二区三曲| 亚洲精品中文字幕无乱码| 久久亚洲精品无码AV红樱桃| 亚洲美女大bbbbbbbbb| 久久久无码精品亚洲日韩京东传媒| 亚洲精品高清国产麻豆专区| 亚洲二区在线视频| 亚洲av永久无码一区二区三区| 羞羞漫画登录页面免费| 伊人免费在线观看| 亚洲免费黄色网址| 免费v片在线观看| 亚洲精品无码mv在线观看网站| 久久久久久久亚洲Av无码| 亚洲欧美日韩综合久久久久| 一级特级aaaa毛片免费观看 | 国产精品亚洲综合久久| 污视频网站免费在线观看| 中文字幕不卡免费视频| 91免费国产在线观看| 国产精品二区三区免费播放心 | 亚洲AV成人无码天堂| 老司机福利在线免费观看| 成全视频在线观看免费| 成人无码区免费A片视频WWW| 亚洲成年看片在线观看| 亚洲国产高清在线精品一区| 免费高清A级毛片在线播放| 99re在线这里只有精品免费| 爽爽日本在线视频免费| 亚洲区小说区图片区QVOD| 亚洲av一本岛在线播放| 四虎精品免费永久免费视频| 3344永久在线观看视频免费首页| 国产国产成年年人免费看片| 亚洲成在人天堂一区二区| 亚洲成a人片在线不卡一二三区| 国产午夜成人免费看片无遮挡 | 免费在线视频一区| 亚洲福利视频网站|