C 對檔案操作

2021-07-03 19:22:48 字數 937 閱讀 6560

c#建立目錄 

// 建立目錄c:\sixage 

directoryinfo d=directory.createdirectory("c:\\sixage"); 

// d1指向c:\sixage\sixage1 

directoryinfo d1=d.createsubdirectory("sixage1"); 

// d2指向c:\sixage\sixage1\sixage1_1 

directoryinfo d2=d1.createsubdirectory("sixage1_1"); 

// 將當前目錄設為c:\sixage 

directory.setcurrentdirectory("c:\\sixage"); 

// 建立目錄c:\sixage\sixage2 

directory.createdirectory("sixage2"); 

// 建立目錄c:\sixage\sixage2\sixage2_1 

directory.createdirectory("sixage2\\sixage2_1");

遞迴刪除資料夾及檔案 

<%@ page language=c#%> 

<%@ import namespace="system.io"%> 

public void deletefolder(string dir) 

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

response.write(dir+" 資料夾刪除成功"); 

} else 

response.write(dir+" 該資料夾不存在"); //如果資料夾不存在則提示 

} protected void page_load (object sender ,eventargs e)   

收藏於 2009-09-25

c 對檔案操作

獲得當前絕對路徑 指定的路徑 絕對路徑 非web程式引用 return 刪除單個檔案 檔案相對路徑 public static bool deletefile string filepath if file.exists fullpath return false 刪除上傳的檔案 及縮圖 publi...

C 對檔案操作小結

private void button2 click object sender,eventargs e private void button1 click object sender,eventargs e 流檔案操作 filestream fs new filestream filepath,...

C 對檔案的操作

c 對檔案的操作方式有兩種 1 通過file類對檔案進行操作 2 通過檔案流對檔案進行操作 file類是乙個靜態類 因此可以直接使用類名去呼叫方法 有以下方法對檔案進行操作 1 exist 判斷指定路徑下的檔案是否存在,形參為指定路徑,存在則返回true 不存在則返回false 2 move 將原來...