国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

一個拷貝整個文件夾(包括子文件夾)的方法(原創)

2024-07-21 02:16:02
字體:
來源:轉載
供稿:網友
注冊會員,創建你的web開發資料庫,
需要引用命名空間:
using system.io;

/// <summary>
  /// 拷貝文件夾(包括子文件夾)到指定文件夾下,源文件夾和目標文件夾均需絕對路徑. 格式: copyfolder(源文件夾,目標文件夾);
  /// </summary>
  /// <param name="strfrompath"></param>
  /// <param name="strtopath"></param>

  //--------------------------------------------------
  //作者:kgdiwss qq:305725744
 //---------------------------------------------------

  public static void copyfolder(string strfrompath,string strtopath)
  {
   //如果源文件夾不存在,則創建
   if (!directory.exists(strfrompath))
   {    
    directory.createdirectory(strfrompath);
   }   

   //取得要拷貝的文件夾名
   string strfoldername = strfrompath.substring(strfrompath.lastindexof("http://") + 1,strfrompath.length - strfrompath.lastindexof("http://") - 1);   

   //如果目標文件夾中沒有源文件夾則在目標文件夾中創建源文件夾
   if (!directory.exists(strtopath + "http://" + strfoldername))
   {    
    directory.createdirectory(strtopath + "http://" + strfoldername);
   }
   //創建數組保存源文件夾下的文件名
   string[] strfiles = directory.getfiles(strfrompath);

   //循環拷貝文件
   for(int i = 0;i < strfiles.length;i++)
   {
    //取得拷貝的文件名,只取文件名,地址截掉。
    string strfilename = strfiles[i].substring(strfiles[i].lastindexof("http://") + 1,strfiles[i].length - strfiles[i].lastindexof("http://") - 1);
    //開始拷貝文件,true表示覆蓋同名文件
    file.copy(strfiles[i],strtopath + "http://" + strfoldername + "http://" + strfilename,true);
   }
  
   //創建directoryinfo實例
   directoryinfo dirinfo = new directoryinfo(strfrompath);
   //取得源文件夾下的所有子文件夾名稱
   directoryinfo[] zipath = dirinfo.getdirectories();
   for (int j = 0;j < zipath.length;j++)
   {
    //獲取所有子文件夾名
    string strzipath = strfrompath + "http://" + zipath[j].tostring();   
    //把得到的子文件夾當成新的源文件夾,從頭開始新一輪的拷貝
    copyfolder(strzipath,strtopath + "http://" + strfoldername);
   }
  }


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 昂仁县| 西青区| 凤阳县| 无棣县| 德保县| 曲麻莱县| 轮台县| 赣州市| 双江| 大同县| 乌拉特前旗| 木兰县| 南昌县| 新巴尔虎右旗| 尼木县| 乐至县| 英山县| 石首市| 安顺市| 博兴县| 安宁市| 如东县| 海口市| 赤城县| 安溪县| 固原市| 涿鹿县| 海晏县| 新邵县| 衢州市| SHOW| 云浮市| 卓尼县| 苗栗县| 黑水县| 瑞安市| 白沙| 泗水县| 丹凤县| 隆回县| 米易县|