win32:
shfileoperation
1. 將 c:/test.txt 拷貝到
d:/shfileopstruct lpsh;
zeromemory(&lpsh,sizeof(lpsh));
lpsh.hwnd= hwnd_desktop;
lpsh.fflags=fof_noconfirmation|fof_******progress ;
lpsh.wfunc=fo_copy; // fo_move 則是移動
lpsh.pfrom= "c:/test.txt";
lpsh.pto = "d:/"
if( 0 != shfileoperation(&lpsh))
2. 刪除 d:/test.txt
shfileopstruct lpsh;
zeromemory(&lpsh,sizeof(lpsh));
lpsh.hwnd= hwnd_desktop;
lpsh.fflags=fof_noconfirmation|fof_******progress ;
lpsh.wfunc=fo_delete;
lpsh.pfrom= "d:/test.txt";
if( 0 != shfileoperation(&lpsh))
createdirectory
createfile
findfirstfile
findnextfile
mfc:
cfilefind
cfile
carchive
win32_find_data filedata;
handle hsearch;
dword dwattrs;
char szdirpath = "c://textro//";
char sznewpath[max_path];
char szhome[max_path];
bool ffinished = false;
// create a new directory.
if (!createdirectory(szdirpath, null))
// start searching for .txt files in the current directory.
hsearch = findfirstfile("*.*", &filedata);
if (hsearch == invalid_handle_value)
// copy each .txt file to the new directory
// and change it to read only, if not already.
while (!ffinished)
}
if (!findnextfile(hsearch, &filedata))
else
}
}
// close the search handle.
if (!findclose(hsearch))
// 遍歷了所有的子目錄,沒有找到單個的檔案
return false;
對檔案的操作
對檔案的操作大致分為3類 第一類為r 唯讀 當進行唯讀操作時,無法對文字進行更改。注意 當進行r操作時游標會移至最前方從而讀取游標後的內容。第二類為w 只寫 當進行只寫操作時,無法對檔案進行讀取操作。注意 當進行只寫操作時會情況檔案裡的內容。第三類為a 只追加 當進行只追加操作時,無法讀取內容。注意...
MFC對檔案的操作
cfile的派生類cstdiofile提供了對檔案進行流式的操作功能。其中函式void cstdiofile writestring lpctstr lpsz 寫入乙個字串,需要給字串lpsz的末尾加上換行標誌 r n 函式bool cstdiofile readstring cstring rst...
對檔案的讀寫操作
c c 寫入 讀出文字檔案 string filename c i.txt streamreader sr new streamreader filename string str sr.readline sr.close rw.writeline 寫入 rw.writeline abc rw.wr...