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

複製檔案時,第一次與第二次的速度不同?

 
haman
中階會員


發表:46
回覆:137
積分:56
註冊:2005-03-10

發送簡訊給我
#1 引用回覆 回覆 發表時間:2006-07-22 15:14:37 IP:211.76.xxx.xxx 未訂閱

複製檔案時,當目的(destination)磁碟中不存在來源檔時,

複製的速度就會比較慢,但當目的(destination)磁碟中存在來源檔時,

速度上就會快很多,但是偵測到有相同名稱的檔案時,

不論是直接覆寫,或是殺掉重建,其結果都一樣,

明明就是一樣的檔案,速度上怎會有如此差異呢?

下面是部份的程式碼,請各位大大幫我解惑,感謝^^

struct Status{
String SourcePath;
String DestPath;
String RateUnit;
bool isSecond;
int DulTime;
long CopyRate;
};

int __fastcall TCopyFiles::Copy(Status *stCopy)
{
int iSourceFileHandle;
int iDestFileHandle;
long iFileLength;
long lFileSize = 0;
int iBytesRead;
int iFileCount;
int iProgressPos;
double dbStart;
double dbStop ;
String strStuMsg;
char *pszBuffer = new char[MAX_FILE_DATA];
try
{
//開啟來源檔
dbStart = Now();
iSourceFileHandle = FileOpen(stCopy->SourcePath, fmOpenRead);

if(iSourceFileHandle == -1)
{ //開檔失敗
strStuMsg = "Sourcefile open faild!!\n";
Memo->Lines->Add(strStuMsg);
FileClose(iSourceFileHandle);
delete [] pszBuffer;
return openSourceErr;
}
iFileLength = FileSeek(iSourceFileHandle,0,2);
FileSeek(iSourceFileHandle,0,0);
//計算檔案存取次數
iFileCount = iFileLength / MAX_FILE_DATA;

//判斷目的檔的檔案是否存在
if(FileExists(stCopy->DestPath))
iDestFileHandle = FileOpen(stCopy->DestPath, fmOpenWrite);
else
iDestFileHandle = FileCreate(stCopy->DestPath);
if(iDestFileHandle == -1)
{ //開檔或建檔失敗
strStuMsg = "Create Destination file faild!!";
Memo->Lines->Add(strStuMsg);
FileClose(iSourceFileHandle);
FileClose(iDestFileHandle);
delete [] pszBuffer;
return openDestErr;
}
//複製
for(int i = 0; i < iFileCount ; i )
{
iBytesRead = FileRead(iSourceFileHandle, pszBuffer, MAX_FILE_DATA);
FileWrite(iDestFileHandle, pszBuffer, MAX_FILE_DATA);
Application->ProcessMessages();
lFileSize = iBytesRead;
//計算進度條百分比
if(stCopy->isSecond)
iProgressPos = ( (lFileSize / (float)lSize ) 1) * 100;
else
iProgressPos = ( lFileSize / (float)lSize ) * 100;
Progress->Position = iProgressPos ;
}
delete [] pszBuffer;
//判斷最未筆資料是否存在
iFileLength = iFileLength % MAX_FILE_DATA;
if(iFileLength > 0)
{
pszBuffer = new char[iFileLength 1];
iBytesRead = FileRead(iSourceFileHandle, pszBuffer, iFileLength);
FileWrite(iDestFileHandle, pszBuffer, iFileLength);
lFileSize = iBytesRead;
if(stCopy->isSecond)
iProgressPos = 200;
else
iProgressPos = 100;
Progress->Position = iProgressPos ;
delete [] pszBuffer;
}
FileClose(iSourceFileHandle);
FileClose(iDestFileHandle);
dbStop = Now();
//計算時間差
stCopy->DulTime = (dbStop - dbStart) * 10000000;
if(stCopy->DulTime == 0)
stCopy->DulTime ;
stCopy->CopyRate = (lFileSize / stCopy->DulTime ) * 100;
stCopy->DulTime /= 100;
stCopy->RateUnit = SizeUnit(&stCopy->CopyRate);
stCopy->RateUnit = "/sec";

}
catch(...)
{
return copyErr;
}
return noErr;
}

系統時間:2024-04-20 0:17:25
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!