C 語言實現建立,刪除和移動資料夾

2021-04-20 08:21:05 字數 682 閱讀 9285

本文採用c#語言實現建立,刪除和移動資料夾,**如下:

使用directory類和directoryinfo類

一:建立資料夾

tryelse

}catch (exception ee)

二:刪除資料夾

tryelse

}catch (exception ee)

三:移動資料夾

源資料夾和目標資料夾要求存在於同乙個硬碟分割槽中否則會操作失敗(操作失敗! 失敗原因:system.io.ioexception: 源路徑和目標路徑必須具有相同的根。移動操作在卷之間無效。 在 system.io.directory.move(string sourcedirname, string destdirname) 在 createdirectory.movebutton_click(object sender, eventargs e) )

tryif (system.io.directory.exists(ddirectorytextbox.text))

system.io.directory.move(sdirectorytextbox.text, ddirectorytextbox.text);

label1.text = "資料夾移動成功! 原始檔已經被移除。目標資料夾為" + dfiletextbox.text;

}catch (exception ee)

C語言實現遞迴刪除資料夾

使用rmdir函式只能刪除空資料夾,對於非空資料夾就無能為力了,這裡給出乙個實現,用來刪除整個資料夾 0 儲存當前絕對路徑 1 開啟要刪除的資料夾 2 進入要刪除的資料夾 3 讀資料夾 4 如果讀到的是資料夾,將當前讀到的資料夾名稱作為引數返回0遞迴 5 如果不為資料夾呼叫remove刪除 6 返回...

C 建立資料夾,刪除資料夾,建立檔案,刪除檔案

protected void button1 click object sender,eventargs e 判斷檔案的存在 else string name getfiles.filename 獲取已上傳檔案的名字 string size getfiles.postedfile.contentle...

C 檔案及資料夾複製,移動,刪除

class file dirmanipulate filemove 源路徑 目標路徑 public static void filemove string srcfilepath,string destfilepath filedelete public static void filedelete...