我怎样拷贝文件夹用代码写?

flying310 2003-08-27 08:16:00
请各位指教,我怎样拷贝整个文件夹到指定的目录呢?
...全文
37 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
flying310 2003-08-28
  • 打赏
  • 举报
回复
to WWWWA(aaaa)
是不是要在use中引用单元,
fansnaf 2003-08-27
  • 打赏
  • 举报
回复
hehe
fhuibo 2003-08-27
  • 打赏
  • 举报
回复
study
flying310 2003-08-27
  • 打赏
  • 举报
回复
to outer2000(天外流星)
谢谢,
outer2000 2003-08-27
  • 打赏
  • 举报
回复
[Now Supported on Windows NT]

Performs a copy, move, rename, or delete operation on a file system object.

WINSHELLAPI int WINAPI SHFileOperation(

LPSHFILEOPSTRUCT lpFileOp
);


Parameters

lpFileOp

Pointer to an SHFILEOPSTRUCT structure that contains information the function needs to carry out the operation.



Return Values

Returns zero if successful or nonzero if an error occurs.

See Also

SHFILEOPSTRUCT
//如果不清楚,那么就GOOGLE搜索吧,呵呵,这招最灵了;
搜索ShFileOperation
flying310 2003-08-27
  • 打赏
  • 举报
回复
我还是不太明白,请那为大虾说清楚点。
WWWWA 2003-08-27
  • 打赏
  • 举报
回复
var
OpStruc: TSHFileOpStruct;
frombuf, tobuf: Array [0..128] of Char;
Begin
FillChar( frombuf, Sizeof(frombuf), 0 );
FillChar( tobuf, Sizeof(tobuf), 0 );
StrPCopy( frombuf, 'd:\brief\*.*' );
StrPCopy( tobuf, 'd:\temp\brief' );
With OpStruc DO Begin
Wnd:= Handle;
wFunc:= FO_COPY;
pFrom:= @frombuf;
pTo:=@tobuf;
fFlags:= FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION;
fAnyOperationsAborted:= False;
hNameMappings:= Nil;
lpszProgressTitle:= Nil;

end;
ShFileOperation( OpStruc );
end;

foreveryday007 2003-08-27
  • 打赏
  • 举报
回复
function TFmMain.CopyDir(sDirName: string; sToDirName: string): Boolean;
begin
if Length(sDirName) <= 0 then
exit;
Result := SelfCopyDir(sDirName, sToDirName);
end;

function TFmMain.SelfCopyDir(sDirName: string; sToDirName: string): Boolean;
var
F : TSearchRec;
t, tfile : string;
sCurDir : string[255];
FindFileData : WIN32_FIND_DATA;
begin
sCurDir := GetCurrentDir;
ChDir(sDirName);
F.FindHandle := FindFirstFile('*.*', FindFileData);
if F.FindHandle <> INVALID_HANDLE_VALUE then
begin
if not DirectoryExists(sToDirName) then
ForceDirectories(sToDirName);
repeat
tfile := FindFileData.cFileName;
if (tfile = '.') or (tfile = '..') then
Continue;
if FindFileData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY then
begin
t := sToDirName + '\' + tfile;
if not DirectoryExists(t) then
ForceDirectories(t);
if sDirName[Length(sDirName)] <> '\' then
CopyDir(sDirName + '\' + tfile, t)
else
CopyDir(sDirName + tfile, sToDirName + tfile);
end
else
begin
t := sToDirName + '\' + tFile;
CopyFile(PChar(tfile), PChar(t), false);
end;
until FindNextFile(F.FindHandle, FindFileData) = false;
FindClose(F);
end
else
begin
ChDir(sCurDir);
result := false;
exit;
end;

ChDir(sCurDir);
result := true;
end;

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧