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

複製目錄時的錯誤

尚未結案
stickitout
一般會員


發表:15
回覆:8
積分:4
註冊:2003-06-03

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-04-18 16:39:19 IP:211.78.xxx.xxx 未訂閱
各位大大好。小弟從貴版上找到有關複製目錄的做法,小弟想把c:\\king複製到F:\\server。    以下是小弟參考貴版的做法       SHFILEOPSTRUCT sfo;    ZeroMemory(&sfo, sizeof(SHFILEOPSTRUCT));    sfo.hwnd=Handle;    sfo.wFunc=FO_COPY;    sfo.fFlags=FOF_SIMPLEPROGRESS | FOF_RENAMEONCOLLISION |    FOF_NOERRORUI |       FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR;    sfo.lpszProgressTitle="Copy files...";    sfo.pFrom="C:\\king\0";    sfo.pTo="F:\\server\0";    SHFileOperation(&sfo);    問題來了…小弟出現下列錯誤。小弟不知道是哪裡錯了。請各位大大指教。       
conundrum
尊榮會員


發表:893
回覆:1272
積分:643
註冊:2004-01-06

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-04-18 18:45:46 IP:61.64.xxx.xxx 未訂閱
http://delphi.ktop.com.tw/topic.php?TOPIC_ID=44009 【問題】Copy某路徑下的所有內容(該目錄下含文件和目錄)到某個路徑下 那就再看看 此版主作法
stickitout
一般會員


發表:15
回覆:8
積分:4
註冊:2003-06-03

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-04-18 19:27:37 IP:211.78.xxx.xxx 未訂閱
不好意思,小弟沒寫過delphi。請問一下有沒有BCB拷貝目錄的範例程式可供參考呢?? 另外,小弟參考貴版上的程式: //////// SHFILEOPSTRUCT sfo; ZeroMemory(&sfo, sizeof(SHFILEOPSTRUCT)); sfo.hwnd=Handle; sfo.wFunc=FO_COPY; sfo.fFlags=FOF_SIMPLEPROGRESS | FOF_RENAMEONCOLLISION | FOF_NOERRORUI | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR; sfo.lpszProgressTitle="Copy files..."; sfo.pFrom="C:\\king\0"; sfo.pTo="F:\\server\0"; SHFileOperation(&sfo); ////////////////////// 出現了上面圖片的錯誤,有沒有大大可以為小弟解惑呢??
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-04-18 22:30:24 IP:61.221.xxx.xxx 未訂閱
引言: 不好意思,小弟沒寫過delphi。請問一下有沒有BCB拷貝目錄的範例程式可供參考呢?? 另外,小弟參考貴版上的程式: //////// SHFILEOPSTRUCT sfo; ZeroMemory(&sfo, sizeof(SHFILEOPSTRUCT)); sfo.hwnd=Handle; sfo.wFunc=FO_COPY; sfo.fFlags=FOF_SIMPLEPROGRESS | FOF_RENAMEONCOLLISION | FOF_NOERRORUI | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR; sfo.lpszProgressTitle="Copy files..."; sfo.pFrom="C:\\king\0"; sfo.pTo="F:\\server\0"; SHFileOperation(&sfo); ////////////////////// 出現了上面圖片的錯誤,有沒有大大可以為小弟解惑呢??
stickitout 你好:
(1)看起來沒有錯吧?會不會是你其他部分的程式碼造成的錯誤訊息呢?
(2)建議你另外建立一個新的專案,只單純的測試這段程式碼,應該就可以釐清
   問題
-- Enjoy Researching & Developing --
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
m8815010
版主


發表:99
回覆:372
積分:289
註冊:2003-11-13

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-04-19 09:59:46 IP:61.63.xxx.xxx 未訂閱
引言: stickitout 你好: (1)看起來沒有錯吧?會不會是你其他部分的程式碼造成的錯誤訊息呢? (2)建議你另外建立一個新的專案,只單純的測試這段程式碼,應該就可以釐清 問題
RaynorPao兄你好< >: 我昨天看到這一篇時,有幫 >! <>>< >! 發表人 -
taishyang
站務副站長


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

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-04-19 15:12:40 IP:140.135.xxx.xxx 未訂閱
引言:請問一下有沒有BCB拷貝目錄的範例程式可供參考呢??
http://delphi.ktop.com.tw/topic.php?TOPIC_ID=41363 目錄處理函式三則:_DelTree(),_XCopy(),_Move() ■ BCB 版本 BY bruce0211 版主
GGL
資深會員


發表:104
回覆:600
積分:335
註冊:2006-11-05

發送簡訊給我
#7 引用回覆 回覆 發表時間:2005-08-15 22:44:38 IP:140.126.xxx.xxx 未訂閱
我無意間看到這一篇,試了一下,也會有那個錯誤訊息,不知道是什麼原因?
ys168
初階會員


發表:3
回覆:24
積分:25
註冊:2005-10-14

發送簡訊給我
#8 引用回覆 回覆 發表時間:2007-02-04 20:50:14 IP:59.117.xxx.xxx 訂閱
// 完整程式碼如下:請參考
// .cpp
//---------------------------------------------------------------------------
#define NO_WIN32_LEAN_AND_MEAN
#include
#include
#include // 為了使用 GlobalFreePtr()
#include
#include
#pragma hdrstop

#include "Unit1.h"
#define BIF_NEWDIALOGSTYLE 0x0040
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
int nFile,nFile2;
AnsiString SourDir,DestDir;
int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lpData);
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lpData)
{
if(uMsg == BFFM_INITIALIZED){
PCSTR prevDir = reinterpret_cast (lpData);
if(DirectoryExists(prevDir)) SendMessage(hwnd, BFFM_SETSELECTION, static_cast (1L), lpData);
}
return 0;
}
//-------------------------------------------------------------------------------------
bool __fastcall SetDirectory(AnsiString StartDir, AnsiString *selDir, AnsiString *dirName)
{
auto bool rc = true;

BROWSEINFO bi;
char PathStr[MAX_PATH];
char FolderName[MAX_PATH];
LPITEMIDLIST ItemID;
memset(&bi, 0, sizeof(BROWSEINFO));
memset(PathStr, 0, MAX_PATH);
bi.hwndOwner = Application->Handle;
bi.pszDisplayName = FolderName;
bi.lpszTitle = "請選擇資料夾:";
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_DONTGOBELOWDOMAIN | BIF_NEWDIALOGSTYLE;
bi.lpfn = reinterpret_cast (BrowseCallbackProc);
bi.lParam = reinterpret_cast (StartDir.c_str());

CoInitialize(NULL);
ItemID = SHBrowseForFolder(&bi);
if(ItemID == NULL){
rc = false;
}else{
SHGetPathFromIDList(ItemID, PathStr);
}
GlobalFreePtr(ItemID);
CoUninitialize();

*selDir = PathStr;
*dirName = FolderName;

return rc;
}
//-----------------------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
AnsiString StartDirectory = "C:\\"; // 設定對話框起始目錄
AnsiString SourceDirectory; // 儲存被選擇目錄的路徑字串
AnsiString DirectoryName; // 儲存被選擇目錄的名稱字串
if(SetDirectory(StartDirectory, &SourceDirectory, &DirectoryName))
{
Edit1->Text=SourceDirectory;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
AnsiString StartDirectory = "C:\\"; // 設定對話框起始目錄
AnsiString DestDirectory; // 儲存被選擇目錄的路徑字串
AnsiString DirectoryName; // 儲存被選擇目錄的名稱字串
if(SetDirectory(StartDirectory, &DestDirectory, &DirectoryName))
{
Edit2->Text=DestDirectory;
}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::DirFiles(AnsiString RootDir, bool chkSubDir, bool incPath)
{
chdir(RootDir.c_str()); // 切換到指定目錄去
TSearchRec Sr; // 設 Sr 為存放檔案資訊的結構變數
AnsiString FileName; // 設定檔案名稱之用的暫存變數

int done = FindFirst("*.*", faDirectory | faAnyFile, Sr);
while (done == 0)
{
if (!(Sr.Attr & faDirectory)) // 如果是檔案
{
if (incPath) // 如果檔名要包含路徑資料在內
{
char curdir[MAXPATH 1];
GetCurrentDirectory(MAXPATH, curdir); // 取得現行目錄名稱
FileName = AnsiString(curdir) "\\" Sr.Name; // 設定含路徑的檔名
nFile ;
}
else // 設定不含路徑的檔名
nFile ;
}
else if(chkSubDir)
{ // 如果要檢查次目錄內的檔案
if (Sr.Name != "." && Sr.Name != "..") // 如果不是相對目錄代碼的話
{
DirFiles(Sr.Name.c_str(), true, incPath); // 如果是目錄的話就遞迴處理
chdir(String("..").c_str()); // 切換回前一層目錄
}
}

done = FindNext(Sr); // 找目錄中的下一個檔案
}
FindClose(Sr);
}
//--------------------------------------------------------------------------

void __fastcall TForm1::Copy_Subdirectory(String PathSource, String PathDest)
{
String st;
if (PathSource[PathSource.Length()] != '\\')
PathSource = String("\\");

if (PathDest[PathDest.Length()] != '\\')
PathDest = String("\\");

String mask = (PathSource "*.*");
WIN32_FIND_DATA fd = {0};
HANDLE h = FindFirstFile(mask.c_str(), &fd); //Win32 API

if(h != INVALID_HANDLE_VALUE)
{
while(FindNextFile(h, &fd) ) //Win32 API
{
String File = fd.cFileName;

if(File == "." || File == "..")
continue;
Application->ProcessMessages();
if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
SourDir = ExtractFileDir(PathSource File);
if(SourDir.Length() == 3)
SourDir = SourDir.UpperCase();
else
{
SourDir = SourDir.SubString(SourDir.LastDelimiter("\\") 1,SourDir.Length());
int lenth=SourDir.Length();
if(lenth>25)
{
SourDir=SourDir.SubString(1,24);
SourDir ="~";
}
}

DestDir = ExtractFileDir(PathDest File);
if(DestDir.Length() == 3)
DestDir= DestDir.UpperCase();
else
{
DestDir = DestDir.SubString(DestDir.LastDelimiter("\\") 1,DestDir.Length());
int lenth2=DestDir.Length();
if(lenth2>25)
{
DestDir=DestDir.SubString(1,24);
DestDir ="~";
}
}
lbl2->Caption = "從【" SourDir "】到【" DestDir "】";

if (!CreateDir(PathDest File)) //VCL function
// ShowMessage("Cannot create directory :" PathDest File);
;
String SourceDir = PathSource File "\\";
String DestDir = PathDest File "\\";

Copy_Subdirectory(SourceDir, DestDir);
Application->ProcessMessages();
}
else
{
st.sprintf("%s%s",PathSource.c_str(),File.c_str());
lbl1->Caption = ExtractFileName(st);
nFile2 ;
if (!CopyFile((PathSource File).c_str(),
(PathDest File).c_str(), FALSE)) //Win32 API
{
void* vpBuffer;

FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM,NULL,
GetLastError(),MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(char*) &vpBuffer,0, NULL);

LocalFree(vpBuffer);
}
Application->ProcessMessages();
}
ProgressBar1->Position = nFile2;
}

FindClose(h); // Win 32 API
}
}

//-----------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(!Edit1->Text.IsEmpty() && !Edit2->Text.IsEmpty())
{
DirFiles(Edit1->Text.c_str(), 1, 1); // 計算檔案大小
ProgressBar1->Min = 0;
ProgressBar1->Max = nFile;
Animate1->Active=true;
RECT r1 = {0,0,432,320};
::AdjustWindowRect(&r1, WS_CAPTION|WS_BORDER, true);
::SetWindowPos(Handle, HWND_TOP,0,0,r1.right-r1.left,r1.bottom-r1.top,SWP_NOMOVE );
StaticText1->Caption="複製中稍後...";
Copy_Subdirectory(Edit1->Text, Edit2->Text);
RECT r2 = {0,0,432,146};
::AdjustWindowRect(&r2, WS_CAPTION|WS_BORDER, true);
::SetWindowPos(Handle, HWND_TOP,0,0,r2.right-r2.left,r2.bottom-r2.top,SWP_NOMOVE );
StaticText1->Caption="複製完畢...";
}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormShow(TObject *Sender)
{
RECT r1 = {0,0,432,146};
::AdjustWindowRect(&r1, WS_CAPTION|WS_BORDER, true);
::SetWindowPos(Handle, HWND_TOP,0,0,r1.right-r1.left,r1.bottom-r1.top,SWP_NOMOVE );

StaticText1->Caption="請選擇來源至目標複製...";
}
//---------------------------------------------------------------------------

// .h 檔如下:
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include
#include
#include
#include <Forms.hpp><br /> #include
#include
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TPanel *Panel1;
TButton *Button1;
TEdit *Edit1;
TLabel *Label1;
TLabel *Label2;
TEdit *Edit2;
TButton *Button2;
TButton *Button3;
TAnimate *Animate1;
TLabel *lbl1;
TLabel *lbl2;
TProgressBar *ProgressBar1;
TStaticText *StaticText1;
void __fastcall Button2Click(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
void __fastcall Button3Click(TObject *Sender);
void __fastcall FormShow(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
void __fastcall DirFiles(AnsiString RootDir, bool chkSubDir, bool incPath);
void __fastcall Copy_Subdirectory(String PathSource, String PathDest);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

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