📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
lst_dir: TListBox;
Button1: TButton;
Button2: TButton;
dlgOpen1: TOpenDialog;
ProgressBar1: TProgressBar;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure DeleteDir(sDirectory: String);
//删除目录和目录下得所有文件和文件夹
var
sr: TSearchRec;
sPath,sFile: String;
begin
//检查目录名后面是否有 '\'
if Copy(sDirectory,Length(sDirectory),1) <> '\' then
sPath := sDirectory + '\'
else
sPath := sDirectory;
//------------------------------------------------------------------
if FindFirst(sPath+'*.*',faAnyFile, sr) = 0 then
begin
repeat
sFile:=Trim(sr.Name);
if sFile='.' then Continue;
if sFile='..' then Continue;
sFile:=sPath+sr.Name;
if (sr.Attr and faDirectory)<>0 then
DeleteDir(sFile)
else if (sr.Attr and faAnyFile) = sr.Attr then
DeleteFile(sFile); //删除文件
until FindNext(sr) <> 0;
FindClose(sr);
end;
RemoveDir(sPath);
//------------------------------------------------------------------
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if dlgOpen1.Execute then
begin
lst_dir.Items.LoadFromFile(dlgOpen1.FileName);
Application.MessageBox('恭喜您,号码导入成功!', '提示', MB_OK +
MB_ICONINFORMATION);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var i:integer;
fileName:string;
begin
ProgressBar1.Position:=0;
for i:=0 to lst_dir.Count-1 do
begin
fileName:=Trim(lst_dir.Items.Strings[i]);
if fileName<>'' then
begin
fileName:=ExtractFilePath(paramstr(0))+fileName;
try
DeleteDir(fileName);
except
end;
ProgressBar1.Position:=Trunc(i/(lst_dir.Count-1)*100+1) ;
end;
end;
Application.MessageBox('已经删除指定的文件!', '提示', MB_OK +
MB_ICONINFORMATION);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -