[問題]動態地複制檔案(目的地可改) |
尚未結案
|
Ross
一般會員 發表:6 回覆:17 積分:4 註冊:2005-03-02 發送簡訊給我 |
在站內搜尋過了...但還是解決不了問題...
我是用OpenDialog先給出目的地,但是copyfile出了問題.試過用StringReplace(),解決"\\"問題...但是還不行呀!!!
void __fastcall TMainForm::FileNew1Execute(TObject *Sender) { AnsiString sz; TReplaceFlags Flags; Flags<發表人 - Ross 於 2005/05/10 22:59:41 |
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
RedSnow
版主 發表:79 回覆:1322 積分:845 註冊:2003-12-15 發送簡訊給我 |
|
Ross
一般會員 發表:6 回覆:17 積分:4 註冊:2005-03-02 發送簡訊給我 |
|
Ross
一般會員 發表:6 回覆:17 積分:4 註冊:2005-03-02 發送簡訊給我 |
引言: Ross 您好: 您將 CopyFile() 的參數放反了,改成如下所示即可: if(CopyFile(sz.c_str(), "_.md_", false))不會把.... Copies the source file to the destination file. function CopyFileTo(const Source: string; const Destination: string): Boolean; Parameters const Source: string Source file name. const Destination: string Destination file name. Returns Boolean - True if the file is copied, False on error. Description CopyFileTo is a function used to copy the file specified in Source to the file specified in Destination. CopyFileTo will return False if the file in Destination already exists. CopyFileTo encapsulates the platform-specific calls needed to perform the file copy operation. On the Windows platform, this is the Win32 API function CopyFile. On the Linux platform, CopyFileTo uses a TFileStream instance to create the destination file. |
RedSnow
版主 發表:79 回覆:1322 積分:845 註冊:2003-12-15 發送簡訊給我 |
Ross 您好: 您在您自己的範例中使用的是 CopyFile() 而不是 CopyFileTo(),CopyTo() 的說明資料如下:
The CopyFile function copies an existing file to a new file. BOOL CopyFile( LPCTSTR lpExistingFileName, // pointer to name of an existing file LPCTSTR lpNewFileName, // pointer to filename to copy to BOOL bFailIfExists // flag for operation if file exists ); Parameters lpExistingFileName Points to a null-terminated string that specifies the name of an existing file. lpNewFileName Points to a null-terminated string that specifies the name of the new file. bFailIfExists Specifies how this operation is to proceed if a file of the same name as that specified by lpNewFileName already exists. If this parameter is TRUE and the new file already exists, the function fails. If this parameter is FALSE and the new file already exists, the function overwrites the existing file and succeeds. |
Ross
一般會員 發表:6 回覆:17 積分:4 註冊:2005-03-02 發送簡訊給我 |
引言: Ross 您好: 您在您自己的範例中使用的是 CopyFile() 而不是 CopyFileTo(),CopyFile() 的說明資料如下:我想大大你唔會了...我是想張"_.md_" copy 到 目的地"sz.c_str()"...The CopyFile function copies an existing file to a new file. BOOL CopyFile( LPCTSTR lpExistingFileName, // pointer to name of an existing file LPCTSTR lpNewFileName, // pointer to filename to copy to BOOL bFailIfExists // flag for operation if file exists ); Parameters lpExistingFileName Points to a null-terminated string that specifies the name of an existing file. lpNewFileName Points to a null-terminated string that specifies the name of the new file. bFailIfExists Specifies how this operation is to proceed if a file of the same name as that specified by lpNewFileName already exists. If this parameter is TRUE and the new file already exists, the function fails. If this parameter is FALSE and the new file already exists, the function overwrites the existing file and succeeds.發表人 - RedSnow 於 2005/05/11 01:02:20 |
RedSnow
版主 發表:79 回覆:1322 積分:845 註冊:2003-12-15 發送簡訊給我 |
Ross 您好: 如果是這樣的話,那麼您最好是將存放 "_.md_" 檔案的路徑一併指定清楚,否則程式會在您指定目標檔案的目錄去讀取 "_.md_" 那個檔案,如果兩個檔案並不是在同一個目錄的話,將會產生錯誤。 如果您的 "_.md_" 檔案與程式放在同一個目錄內,那就改成下列方式試試看:
String tempFile = ExtractFileDir(Application->ExeName) "\\_.md_"; if(CopyFile(tempFile.c_str(),sz.c_str(),false)){ .....發表人 - RedSnow 於 2005/05/11 01:30:36 |
Ross
一般會員 發表:6 回覆:17 積分:4 註冊:2005-03-02 發送簡訊給我 |
引言: Ross 您好: 如果是這樣的話,那麼您最好是將存放 "_.md_" 檔案的路徑一併指定清楚,否則程式會在您指定目標檔案的目錄去讀取 "_.md_" 那個檔案,如果兩個檔案並不是在同一個目錄的話,將會產生錯誤。 如果您的 "_.md_" 檔案與程式放在同一個目錄內,那就改成下列方式試試看:多謝大大指導...我已用getcwd()做了...現在再試一試大大的...超開心... < >....可以早點睡了...< >String tempFile = ExtractFileDir(Application->ExeName) "\\_.md_"; if(CopyFile(tempFile.c_str(),sz.c_str(),false)){ .....發表人 - RedSnow 於 2005/05/11 01:30:36 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |