c 中檔案操作的一些相關函式

2021-09-30 07:42:47 字數 2107 閱讀 7215

1、

///

/// 判斷是否是隱藏檔案

///

/// 檔案路徑

///

public bool ishidden(string path)

else

return false;}

2、 //////建立指定目錄

//////

public void createdirectory(string targetdir)

3、刪除檔案或目錄

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

//////操作目錄

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

public static void deletefiles(string targetdir, bool delsubdir)

if (delsubdir) }

}       

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

//////目錄路徑

public static void deletesubdirectory(string targetdir)}

//////刪除指定目錄,包括當前目錄和所有子目錄和檔案

//////目錄路徑

public static void deletedirectory(string targetdir)}

4、移動(剪下)檔案或目錄

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

//////原始目錄

///目標目錄

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

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

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

}else

}if (movesubdir)}}

5、複製檔案或目錄

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

//////原始目錄

///目標目錄

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

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

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

}else

}//複製子目錄

if (copysubdir)}}

6、掃瞄資料夾及其子目錄

///

/// 獲取子目錄檔案資訊

///

/// 資料夾名稱

public void getchildfileinfo(string targetdir)}

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

catch }

7、將檔案刪除至**站(上面的檔案刪除不經過**站,若要清空**站只需要找到**站所在的路徑呼叫上面的刪除檔案函式)

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.runtime.interopservices; //需要引入   

namespace delrecycled }

} 8、讀取、寫入文字型別的檔案

8.1 讀取

public static string readfile(string filename)}}

return content;}

8.2 寫入

//path為要寫入文字的檔案路徑

//str 為要寫入的字元春

public static void writefile(string path,string str)

{         

//寫入

swt.writeline(str);

swt.close();

fst.close();

一些檔案操作函式

fileage 函式 返回檔案已存在的時間 fileclose 命令 關閉指定的檔案 filecreate 命令 用指定的檔名建立新檔案 filedatetodatetime 函式 將dos的日期格式轉換為delphi的日期格式 fileexists 函式 檢查檔案是否存在 filegatattr ...

檔案操作的一些函式

fileinfo fi new fileinfo filepath file info.check file time or file size long size fi.length 1024 獲取檔案的名稱 fileinfo fi new fileinfo filepath return fi....

檔案操作的一些函式

istream read char s,streamsize n 從流中讀取n個字元放到s指向的陣列中,讀取過程中不會檢查資料 意味著讀取到空格或者 換行符不會停止讀取 也不會自動新增乙個null作為字串結束符,如果碰到eof則函式結束,並置eofbit和failbit為1 如果流中 的字元數目超出...