var
Form1: TForm1;
ini:tinifile;
path,tmp:string;
TimerID: Integer;
implementation
{$R *.dfm}
function ExtractFileNameEx(FileName: string): string; //返回文件名
begin
Result := ExtractFileName(FileName);
Result := Copy(Result, 1, Length(Result) - length(ExtractFileExt(FileName)));
end;
function IsValidFileName(FileName: string): Boolean;
{
判断FileName是否是合法的文件名,是,返回True,否则,返回False;
}
var
i: integer;
begin
result := True;
for i := 1 to Length(FileName) do
if FileName[i] in ['<', '>', '?', '/', '\', ':', '*', '|', '"'] then
begin
result := False;
Exit;
end;
end;
procedure TimerFunc;
begin
application.MessageBox('文件已经创建成功!','提示',MB_OK+MB_ICONINFORMATION);
KillTimer(0, TimerID);
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
edit1.Text:=OpenDialog1.FileName;
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
if OpenDialog1.Execute then
edit2.Text:=OpenDialog1.FileName;
edit3.Text:=ExtractFilePath(OpenDialog1.FileName)+
ExtractFileNameEx(OpenDialog1.FileName)+'_VM'+
ExtractFileExt(OpenDialog1.FileName);
end;
procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
if SaveDialog1.Execute then
edit3.Text:=SaveDialog1.FileName;
end;
procedure TForm1.Button1Click(Sender: TObject);
var M:TStringList;
begin
if (FileExists(edit1.Text)) and (FileExists(edit2.Text)) and (IsValidFileName(ExtractFileNameEx(edit3.Text))) then
begin
tmp:=ExtractFileNameEx(Edit3.Text)+
ExtractFileExt(Edit3.Text);
path := ExtractFilePath(Application.ExeName);
m:=TStringList.Create;
m.Text:='copy '+'"'+edit2.Text+'"'+'/b +'+'"'+edit1.Text+'"'+'/b '+'"'+edit3.Text+'"';
m.SaveToFile(path+'run.bat');
m.Free;
winexec(pchar(path+'run.bat'),SW_HIDE);
ProgressBar1.Position:=20;
sleep(1500);
ProgressBar1.Position:=100;
application.MessageBox(pchar('虚拟文件『'+tmp+' 』已经创建成功!'),'提示',MB_OK+MB_ICONINFORMATION);
ProgressBar1.Position:=0;
deletefile(path+'run.bat');
end;
end;