作者lazybones (懶)
看板C_and_CPP
標題[問題] MoveFile的問題
時間Wed Nov 11 10:04:21 2009
我想將一個選定的檔案move到指定的路徑下
我是使用MoveFile()這個function
int result;
char cNewPathName[256];
char cOldPathName[256];
DWORD nBufferLength = 200; // size of directory buffer
TCHAR CurrentPath[200];
memset( CurrentPath, NULL, sizeof(CurrentPath) );
memset( cNewPathName, NULL, sizeof(cNewPathName) );
memset( cOldPathName, NULL, sizeof(cOldPathName) );
printf("Enter target path >");
gets(cNewPathName);
GetCurrentDirectory(nBufferLength, CurrentPath);
sprintf(cOldPathName, "%s\\%s.%s\0", CurrentPath, FilesName, FilesExt);
result = MoveFile(cOldPathName, cNewPathName);
不過一直失敗 result都收到0的回傳值
麻煩版友幫我診斷一下 Orz
謝謝
--
★
╔╮ ╭═╦╮╭═╦╗╮ ╮╔══╮╭═╦╮╮ ╔╮╔══╮╭══╮
╠╣ ╠═╬╣╭╬╩╯╰╦╦╯╠═╦╮║ ╠╣║║╠╣╠╣ ╰═╦╮
╠╣ ╭║ ╠╣║╰╔╗ ╠╣ ║ ╠╣║ ╠╣║╰╠╣║╰╔╗║ ╠╣
╰╩═╯╰ ╰╝╚═╩╯ ╰╝ ╚═╩╯╰═╩╯╰ ╰╝╚═╩╯╰═╩╯
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.211.0.80
推 VictorTom:""裡應該不用特別加'\0', 另外, 用GetLastError()檢查為 11/11 10:10
→ VictorTom:什麼失敗看看@_@" 11/11 10:11
→ lazybones:對喔...有GetLastError()...大感謝!!!<(_ _)> 11/11 10:33
推 aecho:都用TCHAR了,為什麼還要用char呢? 11/11 12:58
推 VictorTom:對吼, 都忘了這種API要注意TCHAR的問題....XD 11/11 13:01
→ lazybones:嗯 謝謝!! 11/11 13:08