檔案操作類2

2022-01-23 03:23:44 字數 3746 閱讀 7613

using system;

using system.text;

using system.web;

using system.io;

}#endregion

#region 讀檔案

protected string read_txt(string filename)

#endregion

#region 取得檔案字尾名

/****************************************

* 函式名稱:getpostfixstr

* 功能說明:取得檔案字尾名

* 參    數:filename:檔名稱

* 呼叫示列:

*           string filename = "aaa.aspx";       

*           string s = dotnet.utilities.fileoperate.getpostfixstr(filename);        

*****************************************/

///

/// 取字尾名

///

/// 檔名

/// .gif|.html格式

public static string getpostfixstr(string filename)

#endregion

/// 檔案路徑

/// 檔案內容

public static void writefile(string path, string strings)

system.io.streamwriter f2 = new system.io.streamwriter(path, true, system.text.encoding.utf8);

f2.writeline(strings);

f2.close();

f2.dispose();

}#endregion

/// 檔案路徑

///

public static string readfile(string path)

return s;

}#endregion

/// 檔案路徑

/// 內容

/// 原始檔案

/// 新檔案路徑

public static void filecoppy(string orignfile, string newfile)

#endregion

/// 路徑

public static void filedel(string path)

#endregion

/// 原始路徑

/// 新路徑

public static void filemove(string orignfile, string newfile)

#endregion

*****************************************/

///

/// 在當前目錄下建立目錄

///

/// 當前目錄

/// 新目錄

public static void foldercreate(string orignfolder, string newfloder)

///

/// 建立資料夾

///

///

public static void foldercreate(string path)

#endregion

#region 建立目錄

public static void filecreate(string path)

}#endregion

///

///

public static void deletefolder(string dir)

directory.delete(dir, true); //刪除已空資料夾                 }}

#endregion

/// 原始路徑

/// 目標資料夾

public static void copydir(string srcpath, string aimpath)

}catch (exception ee)

}#endregion

*****************************************/

///

/// 獲取指定資料夾下所有子目錄及檔案

///

/// 詳細路徑

public static string getfoldall(string path)

else

rn += _s + "├";

}rn += "" + dirinfo.name.tostring() + "

";fileinfo fileinfo = dirinfo.getfiles();   //目錄下的檔案

foreach (fileinfo finfo in fileinfo)

else

rn += _f + "│ ├";

}rn += finfo.name.tostring() + " ";}

rn = listtreeshow(dirinfo, nlevel + 1, rn);

}return rn;

}/// 詳細路徑

///下拉列表名稱

///預設選擇模板名稱

public static string getfoldall(string path, string dropname, string tplpath)

else

rn += _s + "┣";

}rn += "" + dirinfo.name.tostring() + "";

fileinfo fileinfo = dirinfo.getfiles();   //目錄下的檔案

foreach (fileinfo finfo in fileinfo)

else

rn += _f + "│ ├";

}rn += finfo.name.tostring() + "";

}rn = listtreeshow(dirinfo, nlevel + 1, rn, tplpath);

}return rn;

}#endregion

*****************************************/

///

/// 獲取資料夾大小

///

/// 資料夾路徑

///

public static long getdirectorylength(string dirpath)

directoryinfo dis = di.getdirectories();

if (dis.length > 0)

}return len;

}#endregion

*****************************************/

///

/// 獲取指定檔案詳細屬性

///

/// 檔案詳細路徑

///

"所在目錄:" + objfi.directoryname + "

副檔名:" + objfi.extension;

return str;

}#endregion}}

檔案操作類

把乙個資料夾下所有檔案複製到另乙個資料夾下 當前資料夾 copy到新檔案 public static void copydirectory string srcpath,string destpath copydirectory i.fullname,destpath i.name 遞迴呼叫複製子資...

檔案操作2

2972 c語言習題5.24 檔案操作1 時間限制 1 sec 記憶體限制 128 mb 提交 248 解決 94 145811 fuxin 100 145811 chengxian 90 145812 zhangxue 92 145812 lijun 88 檔案中儲存的學生資訊按照班級編號公升序排...

檔案操作(2)

建立目錄 mkdir aa 刪除目錄 目錄必須為空才可以刪除 rmdir img 移動目錄檔案 rename img ajax img 建立檔案 touch 11.txt 複製檔案 copy 11.txt ajax 11.txt 刪除檔案 unlink 11.txt 讀取檔案內容 本地,遠端 ech...