API檔案 夾 操作總結 拷貝 刪除等

2021-09-08 03:17:25 字數 1773 閱讀 2215

//

刪除檔案或者資料夾

bool deletefile(string

strpath)

; fileop.fflags = //

fof_allowundo |

//允許放回**站

fof_noconfirmation | //

不出現確認對話方塊

fof_noerrorui; //

不出現錯誤對話方塊

fileop.pfrom =ppath;

fileop.pto = null; //

一定要是null

fileop.wfunc = fo_delete; //

刪除操作

bool bresult = (shfileoperation(&fileop) == 0

); delete ppath;

return

bresult;}//

複製檔案或資料夾

bool copyfile(string strfrom,string

strto)

; fileop.fflags = fof_noconfirmation| //

不出現確認對話方塊

fof_noconfirmmkdir ; //

需要時直接建立乙個資料夾,不需使用者確定

fileop.pfrom =pfrom;

fileop.pto =pto;

fileop.wfunc =fo_copy;

bool bresult = (shfileoperation(&fileop) == 0

); delete pfrom;

delete pto;

return

bresult;}//

移動檔案或資料夾

bool movefile(string strfrom,string

strto)

; fileop.fflags = fof_noconfirmation| //

不出現確認對話方塊

fof_noconfirmmkdir ; //

需要時直接建立乙個資料夾,不需使用者確定

fileop.pfrom =pfrom;

fileop.pto =pto;

fileop.wfunc =fo_move;

bool bresult = (shfileoperation(&fileop) == 0

); delete pfrom;

delete pto;

return

bresult;}//

從命名檔案或資料夾

bool renamefile(string strfrom,string

strto)

; fileop.fflags = fof_noconfirmation; //

不出現確認對話方塊

fileop.pfrom =pfrom;

fileop.pto =pto;

fileop.wfunc =fo_rename;

bool bresult = (shfileoperation(&fileop) == 0

); delete pfrom;

delete pto;

return

bresult;

}

shfileoperation操作,如果是相對路徑需要後面兩個'\0',如"..\\x.xml\0",包括自身的\0

擴充套件閱讀:

拷貝檔案 資料夾 建立資料夾 刪除資料夾操作

qt拷貝檔案 資料夾 建立資料夾 刪除資料夾操作 cpp view plain copy brief 拷貝檔案到目的資料夾 param srcfilename 原始檔全路徑,比如 f tx wwxx.txt f tx des desd param desfilepathname 要copy到的目的路...

遞迴刪除資料夾跟拷貝資料夾

刪除檔案 存在檔案則直接刪除返回true,如果不存在返回false 刪除目錄 為空 直接刪除 不為空 刪不掉 需要先刪除資料夾裡面所有檔案,再刪除資料夾 不存在直接返回false 注意 delete方法 直接從磁碟中刪除,不能像 站一樣可以恢復 遞迴拷貝資料夾 param oldfile 源資料夾 ...

拷貝資料夾

需要引用命名空間 using system.io 拷貝資料夾 包括子資料夾 到指定資料夾下,源資料夾和目標資料夾均需絕對路徑.格式 copyfolder 源資料夾,目標資料夾 public static void copyfolder string strfrompath,string strtop...