📄 巨菜的问题:如何实现文件的拷贝,移动,删除;目录(子目录)的创建、删除?.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0055)http://www.delphibbs.com/delphibbs/dispq.asp?lid=927897 -->
<HTML xmlns:tools><HEAD><TITLE>大富翁论坛 delphibbs.com</TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<META content=大富翁,论坛,技术,积分,排行榜,Delphi,Kylix,Java,XML,XSLT,forum name=keywords>
<META
content="大富翁论坛(delphibbs.com)关于 Delphi, Kylix, Java 的技术论坛。采用积分游戏形式,靠您的智慧上大富翁排行榜!"
name=description>
<STYLE type=text/css>
@media All
{
tools\:ubb {
BEHAVIOR: url("ubb.htc")
}
}
</STYLE>
<LINK href="巨菜的问题:如何实现文件的拷贝,移动,删除;目录(子目录)的创建、删除?.files/web_font.css"
rel=stylesheet type=text/css>
<SCRIPT src="巨菜的问题:如何实现文件的拷贝,移动,删除;目录(子目录)的创建、删除?.files/loadxmln.js"></SCRIPT>
<META content="MSHTML 5.00.2614.3500" name=GENERATOR></HEAD>
<BODY onload=showMsg();show() topMargin=2>
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 width="100%">
<TBODY>
<TR>
<TD align=middle><A
href="http://www.delphibbs.com/delphibbs/rules.asp">游戏规则</A> <A
href="http://www.delphibbs.com/delphibbs/register.asp">免费注册</A> <IMG
align=middle height=60
src="巨菜的问题:如何实现文件的拷贝,移动,删除;目录(子目录)的创建、删除?.files/dfwlogo.gif" width=240> <A
href="http://www.delphibbs.com/delphibbs/download.asp">资料下载</A> <A
href="http://www.delphibbs.com/delphibbs/index.asp">关于本站</A> </TD></TR>
<TR>
<TD align=middle colSpan=2><A
href="http://www.delphibbs.com/delphibbs/listroom.asp">问题分类</A> <A
href="http://www.delphibbs.com/delphibbs/listq.asp">问题列表</A> <A
href="http://www.delphibbs.com/delphibbs/listu.asp">富翁列表</A> <A
href="http://www.delphibbs.com/delphibbs/dispu.asp">我的信息</A> <A
href="http://www.delphibbs.com/delphibbs/askqn.asp">提出问题</A> <A
href="http://www.delphibbs.com/delphibbs/uonline.asp">在线富翁</A> <A
href="http://www.delphibbs.com/delphibbs/calendar.asp">富翁日历</A> <A
href="http://richsearch.com/" target=_blank>全文检索</A> 大富翁练功场
</TD></TR></TBODY></TABLE><xml id=menuxml><?xml version="1.0" encoding="gb2312" ?><DFWML type="注册信息"><URL>/delphibbs/dispq.asp</URL><QUERY_STRING>lid=927897</QUERY_STRING><USER Name="earlc"><points>1620</points><expoints>0</expoints><earnings>0</earnings><gettimes>8</gettimes><usertype>0</usertype><lasttime>2002-11-18 20:58:00</lasttime></USER><USER Name="" /></DFWML></xml><xml id=menuxsl src="login.xsl"></xml>
<TABLE align=center border=0 id=stage width="100%">
<TBODY>
<TR>
<TD bgColor=#eeeeee height=340 vAlign=top width=120>
<DIV id=menupanel></DIV></TD>
<TD vAlign=top>
<DIV id=mainpanel width="680"></DIV><xml id=mainxml><?xml version="1.0" encoding="gb2312" ?><DFWML type="问题显示" title="巨菜的问题:如何实现文件的拷贝,移动,删除;目录(子目录)的创建、删除?">
<Q ID="927897" status="2"><subject><![CDATA[巨菜的问题:如何实现文件的拷贝,移动,删除;目录(子目录)的创建、删除?]]></subject><from>johnrain</from>
<content><![CDATA[我刚刚接触delphi,想实现上述操作。请别笑话我。]]></content><points>20</points><read_n>61</read_n><reply_n>4</reply_n><regdatetime>2002-2-19 17:55:00</regdatetime><datetime>2002-4-3 11:02:00</datetime><room>软件工程</room><master>房客</master><master2>taozhiyu</master2><expert>eulb-10,xiaotian2002-10,</expert></Q>
<REPLY><Q ID="927953"><from>eulb</from><datetime>2002-2-19 18:20:00</datetime>
<content><![CDATA[MkDir(str);
ChDir(str);
GetDir(DriveID,str);
SetCurrentDir(str);
IOResult --上面几个过程调用成功即返回0值
{This way uses a File stream.}
Procedure FileCopy( Const sourcefilename, targetfilename: String );
Var
S, T: TFileStream;
Begin
S := TFileStream.Create( sourcefilename, fmOpenRead );
try
T := TFileStream.Create( targetfilename,
fmOpenWrite or fmCreate );
try
T.CopyFrom(S, S.Size ) ;
finally
T.Free;
end;
finally
S.Free;
end;
End;
{This way uses memory blocks for read/write.}
procedure FileCopy(const FromFile, ToFile: string);
var
FromF, ToF: file;
NumRead, NumWritten: Word;
Buf: array[1..2048] of Char;
begin
AssignFile(FromF, FromFile);
Reset(FromF, 1); { Record size = 1 }
AssignFile(ToF, ToFile); { Open output file }
Rewrite(ToF, 1); { Record size = 1 }
repeat
BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
BlockWrite(ToF, Buf, NumRead, NumWritten);
until (NumRead = 0) or (NumWritten <> NumRead);
CloseFile(FromF);
CloseFile(ToF);
end;
{This one uses LZCopy, which USES LZExpand.}
procedure CopyFile(FromFileName, ToFileName: string);
var
FromFile, ToFile: File;
begin
AssignFile(FromFile, FromFileName); { Assign FromFile to FromFileName }
AssignFile(ToFile, ToFileName); { Assign ToFile to ToFileName }
Reset(FromFile); { Open file for input }
try
Rewrite(ToFile); { Create file for output }
try
{ copy the file an if a negative value is returned }
{ raise an exception }
if LZCopy(TFileRec(FromFile).Handle, TFileRec(ToFile).Handle) < 0
then
raise EInOutError.Create('Error using LZCopy')
finally
CloseFile(ToFile); { Close ToFile }
end;
finally
CloseFile(FromFile); { Close FromFile }
end;
end;
]]></content></Q>
<Q ID="934877"><from>kingdeezj</from><datetime>2002-2-22 13:28:00</datetime>
<content><![CDATA[你上述的几个操作,都可以利用WINDOW API 函数来解决。你可以在DELPHI HELP 中的
WINDOWS SDK 中找到相应的函数,用法都挺简单的。
]]></content></Q>
<Q ID="935077"><from>xiaotian2002</from><datetime>2002-2-22 14:36:00</datetime>
<content><![CDATA[删除目录:
function DelDirectory(const Source:string): boolean;
var
fo: TSHFILEOPSTRUCT;
begin
FillChar(fo, SizeOf(fo), 0);
with fo do
begin
Wnd := 0;
wFunc := FO_DELETE;
pFrom := PChar(source+#0);
pTo := #0#0;
fFlags := FOF_NOCONFIRMATION+FOF_SILENT;
end;
Result := (SHFileOperation(fo) = 0);
end;
复制目录:
function CopyDirectory(const Source, Dest: string): boolean;
var
fo: TSHFILEOPSTRUCT;
begin
FillChar(fo, SizeOf(fo), 0);
with fo do
begin
Wnd := 0;
wFunc := FO_COPY;
pFrom := PChar(source+#0);
pTo := PChar(Dest+#0);
fFlags := FOF_NOCONFIRMATION+FOF_NOCONFIRMMKDIR ;
end;
Result := (SHFileOperation(fo) = 0);
end;
重新命名:
用MoveFile()或者下面的函数也可以。
RenameFile('c:\a','c:\b')好想也可以?Win2K。
//RenDirectory('d:\wt2','d:\bcde');
function RenDirectory(const OldName,NewName:string): boolean;
var
fo: TSHFILEOPSTRUCT;
begin
FillChar(fo, SizeOf(fo), 0);
with fo do
begin
Wnd := 0;
wFunc := FO_RENAME;
pFrom := PChar(OldName+#0);
pTo := pchar(NewName+#0);
fFlags := FOF_NOCONFIRMATION+FOF_SILENT;
end;
Result := (SHFileOperation(fo) = 0);
end;
//Copy 多个文件的处理:
function CopyFiles(const Source,Dest: string): boolean;
var
fo: TSHFILEOPSTRUCT;
begin
FillChar(fo, SizeOf(fo), 0);
with fo do
begin
Wnd := 0;
wFunc := FO_COPY;
pFrom := @source[1];
pTo :=pchar(dest);
fFlags := FOF_NOCONFIRMATION+FOF_NOCONFIRMMKDIR ;
end;
Result := (SHFileOperation(fo) = 0);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
str:string;
i:integer;
begin
if opendialog1.Execute then
begin
for i:=0 to OpenDialog1.Files.Count-1 do
str:=str+OpenDialog1.Files.strings[i]+#0;
showmessage(str);
str:=str+#0;
CopyFiles(str,'d:\temp');
end;
end;
]]></content></Q>
<Q ID="1020153"><from>johnrain</from><datetime>2002-4-3 11:02:00</datetime>
<content><![CDATA[多人接受答案了。]]></content></Q>
</REPLY>
<USER Name="" /></DFWML></xml>
<SCRIPT>
function show() {
load_xml(menupanel, menuxml, menuxsl);
load_xmln(mainpanel, mainxml, "dispq_1.xsl");
}
function changeFontSize(size) {
obj = document.getElementById('mainpanel');
if (!obj) alert('not found');
for (var ii=0; ii < obj.all.tags('TD').length; ii++) {
var td = obj.all.tags("TD").item(ii);
td.style.fontFamily = "宋体";
td.style.fontSize = size;
td.style.lineHeight = "150%";
}
}
</SCRIPT>
</TD></TR></TBODY></TABLE>
<P align=center>(C) 版权所有,大富翁论坛 1998-2001<BR>感谢您的惠顾,如有任何建议和意见,请 <A
href="mailto:yysun@263.net">联系版主</A>。<FONT
face=Arial><SMALL>2001.4.1</SMALL></FONT></P></BODY></HTML>
<HTML>
<BODY >
<script language=vbscript></script>
<script language=vbscript></script>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -