国产探花免费观看_亚洲丰满少妇自慰呻吟_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);
   }
  }


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 澄城县| 安福县| 乌苏市| 清河县| 连江县| 辽阳市| 乌拉特中旗| 三江| 无为县| 黄陵县| 蒙自县| 海阳市| 夹江县| 元氏县| 康平县| 龙南县| 剑川县| 文登市| 南康市| 延吉市| 丹凤县| 恩平市| 遂昌县| 名山县| 宁蒗| 秭归县| 扎囊县| 阿荣旗| 始兴县| 南涧| 尼勒克县| 义乌市| 方正县| 房山区| 马公市| 榕江县| 巍山| 专栏| 周宁县| 井陉县| 德安县|