C 目錄檔案複製 建立操作

2021-05-28 01:06:22 字數 2708 閱讀 1822

using system;

using system.data;

using system.configuration;

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.xml;

namespace filecopy

/// /// 複製指定目錄的所有檔案,不包含子目錄及子目錄中的檔案

///

/// 原始目錄

/// 目標目錄

/// 如果為true,表示覆蓋同名檔案,否則不覆蓋

public static void copyfiles(string sourcedir, string targetdir, bool overwrite)

/// /// 複製指定目錄的所有檔案

///

/// 原始目錄

/// 目標目錄

/// 如果為true,覆蓋同名檔案,否則不覆蓋

/// 如果為true,包含目錄,否則不包含

public static void copyfiles(string sourcedir, string targetdir, bool overwrite, bool copysubdir)

}else

}//複製子目錄

if (copysubdir)}}

/// /// 剪下指定目錄的所有檔案,不包含子目錄

///

/// 原始目錄

/// 目標目錄

/// 如果為true,覆蓋同名檔案,否則不覆蓋

public static void movefiles(string sourcedir, string targetdir, bool overwrite)

/// /// 剪下指定目錄的所有檔案

///

/// 原始目錄

/// 目標目錄

/// 如果為true,覆蓋同名檔案,否則不覆蓋

/// 如果為true,包含目錄,否則不包含

public static void movefiles(string sourcedir, string targetdir, bool overwrite, bool movesubdir)

}else

}if (movesubdir)}}

/// /// 刪除指定目錄的所有檔案,不包含子目錄

///

/// 操作目錄

public static void deletefiles(string targetdir)

/// /// 刪除指定目錄的所有檔案和子目錄

///

/// 操作目錄

/// 如果為true,包含對子目錄的操作

public static void deletefiles(string targetdir, bool delsubdir)

if (delsubdir)}}

/// /// 建立指定目錄

///

///

public static void createdirectory(string targetdir)

/// /// 建立子目錄

///

/// 目錄路徑

/// 子目錄名稱

public static void createdirectory(string parentdir, string subdirname)

/// /// 刪除指定目錄

///

/// 目錄路徑

public static void deletedirectory(string targetdir)

}/// /// 刪除指定目錄的所有子目錄,不包括對當前目錄檔案的刪除

///

/// 目錄路徑

public static void deletesubdirectory(string targetdir)

}/// /// 將指定目錄下的子目錄和檔案生成xml文件

///

/// 根目錄

/// 返回xmldocument物件

public static xmldocument createxml(string targetdir)

foreach (string directory in directory.getdirectories(targetdir))

return mydocument;

}/// /// 生成xml分支

///

/// 子目錄

/// 父目錄xmldocument

/// xmldocument物件

private static void createbranch(string targetdir, xmlelement xmlnode, xmldocument mydocument)

foreach (string directory in directory.getdirectories(targetdir))}}

}

檔案目錄複製

private void copydir string srcpath string aimpath 判斷目標目錄是否存在如果不存在則新建 if system.io directory exists aimpath 得到源目錄的檔案列表,該裡面是包含檔案以及目錄路徑的乙個陣列 如果你指向copy目標...

實現目錄拷貝 複製目錄 複製檔案

include include include include include include include ifndef debug define pdebug fmt,args.do while 0 else define pdebug fmt,args.printf s d fmt,func...

UNIX 建立 複製 移動 刪除 檔案或目錄

touch 建立檔案 touch file1,如果檔案沒有存在,則會建立,如果此檔案已經存在則會更新檔案的修改日期.其實建立檔案還有其它方式比如用復位向 echo content tmp file1,什麼是復位向,我們在shell程式設計欄目會講到 mkdir 建立目錄 mkdir dir1 這些指...