I
import
Unregistered / Unconfirmed
GUEST, unregistred user!
删除目录: 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;
复制目录:
///复制Source整个目录到DEST目录,如果Dest不存在,自动建立,如果DEST存在,那么Source将作为Dest的子目录!
//例如如果要复制E:整个目录到E:/u37027那么代码为: copydirectory('e:','e;
///如果要复制E:到E:目录下面,那么代码为:CopyDirecotry('E:','E:');
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:','c:<b>')好想也可以?Win2K。
//RenDirectory('d:','d:');
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+#0;
showmessage(str);
str:=str+#0;
CopyFiles(str,'d:');
end;
end;
</b>
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;
复制目录:
///复制Source整个目录到DEST目录,如果Dest不存在,自动建立,如果DEST存在,那么Source将作为Dest的子目录!
//例如如果要复制E:整个目录到E:/u37027那么代码为: copydirectory('e:','e;
///如果要复制E:到E:目录下面,那么代码为:CopyDirecotry('E:','E:');
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:','c:<b>')好想也可以?Win2K。
//RenDirectory('d:','d:');
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+#0;
showmessage(str);
str:=str+#0;
CopyFiles(str,'d:');
end;
end;
</b>