//恢复默认桌面快捷方式图标
//恢复默认桌面快捷方式图标
//移动文件夹中的文件和文件夹并且保留原主文件夹
unit Unit1;
interface
uses
Windows,
Messages,
SysUtils,
Variants,
Classes,
Graphics,
Controls,
Forms,
Dialogs,
Shellapi,
StdCtrls; //记得 use Shellapi
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1 : TForm1;
implementation
{$R *.dfm}
{
不要弹出确认覆盖对话框,可以,设置那个Flag,
F.fFlags := FOF_ALLOWUNDO or FOF_RENAMEONCOLLISION or FOF_NOCONFIRMATION;
而且,你可以隐藏掉进度条以及不允许取消等。只需要设置FLAG
可以禁止取消,应该怎么做?
设置参数FOF_SILENT,就不弹出拷贝界面了。也就没法取消了,对了,那个allowundo也
不设置了,否则可以按右键选择撤销复制。。。
}
function MyCopyFile(SourceName, TargetName: string): Boolean;
var
F : TShFileOpStruct;
begin
F.wnd := Form1.Handle;
F.wFunc := FO_COPY; {操作方式}
F.pFrom := PChar(SourceName + #0#0);
F.pTo := PChar(TargetName + #0#0);
F.fFlags := FOF_ALLOWUNDO or FOF_RENAMEONCOLLISION
or FOF_NOCONFIRMATION or FOF_SILENT;
result := ShFileOperation(F) = 0;
end;
function MyMoveFile(SourceName, TargetName: string): Boolean;
var
F : TShFileOpStruct;
begin
F.wnd := Form1.Handle;
F.wFunc := FO_MOVE; {操作方式}
F.pFrom := PChar(SourceName + #0#0);
F.pTo := PChar(TargetName + #0#0);
F.fFlags := FOF_SILENT or FOF_NOCONFIRMATION;
{
FOF_MULTIDESTFILES or
FOF_CONFIRMMOUSE or
FOF_SILENT or
FOF_RENAMEONCOLLISION or
FOF_NOCONFIRMATION or
FOF_WANTMAPPINGHANDLE or
FOF_ALLOWUNDO or
FOF_FILESONLY or
FOF_SIMPLEPROGRESS or
FOF_NOCONFIRMMKDIR or
FOF_NOERRORUI;
}
result := ShFileOperation(F) = 0;
end;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
var
SrcPath : string;
SrcPath1 : string;
DstPath : string;
begin
Application.ShowMainForm := False;
//当按下按钮是移动 c:\Temp 中的文件和文件夹到 c:\MyFold
//(不提示覆盖,不允许取消复制)
//path:=extractfilepath(application.exename);
SrcPath := 'C:\Users\Public\Desktop\*.*';
SrcPath1 := 'D:\Personal\桌面\*.*';
DstPath := 'D:\Personal\桌面图标备份\';
if DirectoryExists(DstPath) = false then
ForceDirectories(DstPath);
DeleteFile('C:\Users\Public\Desktop\Desktop.ini');
myMoveFile(PChar(SrcPath), PChar(DstPath));
myMoveFile(PChar(SrcPath1), PChar(DstPath));
MyCopyFile('D:\Personal\默认桌面图标\*.*', 'D:\Personal\桌面\');
Application.Terminate;
end;
end.