全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1533
推到 Plurk!
推到 Facebook!

[問題]動態地複制檔案(目的地可改)

尚未結案
Ross
一般會員


發表:6
回覆:17
積分:4
註冊:2005-03-02

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-05-10 20:09:29 IP:202.175.xxx.xxx 未訂閱
在站內搜尋過了...但還是解決不了問題... 我是用OpenDialog先給出目的地,但是copyfile出了問題.試過用StringReplace(),解決"\\"問題...但是還不行呀!!!  
 
void __fastcall TMainForm::FileNew1Execute(TObject *Sender)
{
   AnsiString sz;
   TReplaceFlags Flags;
   Flags<Title="Give a name";
        if (OpenDialog->Execute()){
                sz=OpenDialog->FileName.c_str();
                ShowMessage(sz);
                //AnsiString sz1=StringReplace(sz, "\\", "\\\\", Flags);
                //ShowMessage(sz1);
           if(CopyFile("_.md_",sz.c_str(),false))
                CreateMDIChild(OpenDialog->FileName);
           else{
                GetLastError();
                ShowMessage("Cannot copy file - errno = "   String(errno));
           }
        }
}    
發表人 - Ross 於 2005/05/10 22:59:41
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-05-10 21:41:02 IP:218.168.xxx.xxx 未訂閱
您好:    PO程式碼的方式請參考版規說明,煩請修改謝謝您的配合 >
RedSnow
版主


發表:79
回覆:1322
積分:845
註冊:2003-12-15

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-05-10 21:57:02 IP:219.137.xxx.xxx 未訂閱
Ross 您好:    您將 CopyFile() 的參數放反了,改成如下所示即可:    if(CopyFile(sz.c_str(), "_.md_", false))
Ross
一般會員


發表:6
回覆:17
積分:4
註冊:2005-03-02

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-05-10 23:02:44 IP:202.175.xxx.xxx 未訂閱
引言: 您好: PO程式碼的方式請參考版規說明,煩請修改謝謝您的配合 > < face="Verdana, Arial, Helvetica"> Sorry...
Ross
一般會員


發表:6
回覆:17
積分:4
註冊:2005-03-02

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-05-11 00:04:46 IP:202.175.xxx.xxx 未訂閱
引言: 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

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-05-11 00:59:59 IP:219.137.xxx.xxx 未訂閱
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

發送簡訊給我
#7 引用回覆 回覆 發表時間:2005-05-11 01:06:39 IP:202.175.xxx.xxx 未訂閱
引言: Ross 您好: 您在您自己的範例中使用的是 CopyFile() 而不是 CopyFileTo(),CopyFile() 的說明資料如下:
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
我想大大你唔會了...我是想張"_.md_" copy 到 目的地"sz.c_str()"...
RedSnow
版主


發表:79
回覆:1322
積分:845
註冊:2003-12-15

發送簡訊給我
#8 引用回覆 回覆 發表時間:2005-05-11 01:20:04 IP:219.137.xxx.xxx 未訂閱
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

發送簡訊給我
#9 引用回覆 回覆 發表時間:2005-05-11 01:47:17 IP:202.175.xxx.xxx 未訂閱
引言: 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
多謝大大指導...我已用getcwd()做了...現在再試一試大大的...超開心... < >....可以早點睡了...< >
系統時間:2024-04-29 10:35:52
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!