提交 dcbc1b22 编写于 作者: cz_012273's avatar cz_012273

上传新文件

上级 9a0a45a2
unit wjzl_1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, inifiles, ComCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
ComboBox1: TComboBox;
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
ListView1: TListView;
procedure FormCreate(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure ListView1ColumnClick(Sender: TObject; Column: TListColumn);
procedure ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
Data: Integer; var Compare: Integer);
procedure ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Dirconfig :string = ''; //配置文件路径变量
m_bSort:boolean =false; //排序方向全局变量
implementation
uses wjzl_Unit2,wjzl_myfunc; //引用子窗体form2、自定义函数单元
//用于将目录进行移动
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
SearchRec:TSearchRec; //下面有详解
found:integer;
MyIni :Tinifile; //ini文件类型
strs :TStrings; //字符串列表类型
i :Integer;
Tct: _SystemTime;
Temp: _FileTime;
Dt: TDateTime;
DTstr :string;
begin
//判断配置文件是否存在,并赋值路径变量
if not(FileExists('C:\config.ini') or FileExists('D:\config.ini') or FileExists('config.ini')) then
begin
showmessage('这是您首次使用本程序,请进入后先设定目标文件夹(点“设置”按钮,可设定最少1个、最多6个目标文件夹),目标文件夹设定后可以随时修改。');
end
else
begin
if FileExists('C:\config.ini') then Dirconfig := 'C:\'
else if FileExists('C:\config.ini') then Dirconfig := 'D:\'
else Dirconfig := '';
end;
//提取当前目录所有文件列表
found:=FindFirst(ExtractFilePath(ParamStr(0))+'*.*',faAnyFile,SearchRec);
//ExtractFilePath(ParamStr(0))程序当前所在目录
ListView1.Clear;
ListView1.Columns.Clear;
with listview1 do
begin
Columns.Add;
Columns.Add;
ViewStyle:=vsreport;
GridLines:=true;
columns.items[0].caption:='文件名';
columns.items[1].caption:='创建时间';
Columns.Items[0].Width:=-1;
Columns.Items[1].Width:=-1;
end;
while found=0 do
begin
if (SearchRec.Name<>'.') and (SearchRec.Name<>'..')
and (pos('.lnk',SearchRec.Name)=0)
and (pos('.exe',SearchRec.Name)=0)
{and (SearchRec.Attr<>faDirectory)} then //好像是判断文件夹
with listview1.items.add do
begin
caption:=SearchRec.Name;
//文件创建时间格式转换
FileTimeToLocalFileTime(SearchRec.FindData.ftCreationTime, Temp);
FileTimeToSystemTime(Temp, Tct);
DT := systemTimeToDateTime(Tct);
DTstr := formatdatetime('yyyy/mm/dd hh:mm:ss',DT);
//
subitems.add(DTstr);
end;
found:=FindNext(SearchRec);
end;
FindClose(SearchRec);
//清除memo1显示内容
memo1.Clear;
//从当前配置文件config.ini中添加combobox1选项
ComboBox1.Clear;
ComboBox1.text := '从下拉列表中选择目标文件夹--->';
MyIni := Tinifile.Create(Dirconfig + 'config.ini');
strs := TStringList.Create;
Myini.readsectionvalues('Setting',strs);
for i := 0 to strs.Count-1 do
begin
ComboBox1.Items.Add(strs.ValueFromIndex[i]);
end;
MyIni.Free;
ActiveControl := listview1; //操作焦点放在listview1上
//显示当前目录
label1.Caption := '当前目录'+ExtractFilePath(ParamStr(0))+'文件';
//m_bSort:=false;
end;
//当目标文件夹下拉列表选择项改变时触发
procedure TForm1.ComboBox1Change(Sender: TObject);
var
i :Integer;
begin
if (listview1.Items.count<>0) and (listview1.itemindex>=0) then
begin
memo1.Lines.Add(ListView1.Selected.Caption + '--->' + combobox1.Text);
i:= listview1.itemindex;
listview1.DeleteSelected;
if listview1.Items.count<>0 then
begin
if i= listview1.Items.count then
ListView1.Items[0].Selected := True
else
ListView1.Items[i].Selected := True;
end;
end
else
showmessage('文件列表为空或未选择文件!请确认。');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
vname,vname1,vname2:string;
samefiles: Integer;
begin
samefiles:=0; //重名文件数
repeat
if memo1.Lines.Count > 0 then
begin
vname:= memo1.Lines[0];
vname1:= copy(vname,1,pos('--->',vname)-1);
vname2:= copy(vname,pos('--->',vname)+4,length(vname)-pos('>',vname));
{if pos('.',vname1)<>0 then
MoveFile(PChar(vname1),PChar(vname2 + vname1)) //移动文件操作
else}
WinMovepath(handle,vname1,vname2,false,false); //移动文件夹操作
if not(FileExists(vname1)) then
memo1.Lines.Delete(0) //删除当前文件移动记录
else
inc(samefiles); //重名文件数自加1
if memo1.Lines.Count = 0 then
showmessage('移动列表已整理完毕,请继续选择或退出。')
else if memo1.Lines.Count = samefiles then
showmessage('移动列表已整理完毕,有'+inttostr(samefiles)+'个重名文件(或文件夹)无法移动,请退出后查看。');
end
else
showmessage('移动列表为空!请继续选择或退出。');
until memo1.Lines.Count = samefiles ;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;
procedure TForm1.Button3Click(Sender: TObject);
Var
MyIni :Tinifile;
i :Integer;
//读取子窗体form2中各目标文件夹初始值
begin
form2.Show;
MyIni := Tinifile.Create(Dirconfig + 'config.ini');
for i := 1 to 6 do
begin
(form2.FindComponent('Edit'+inttostr(i)) as TEdit).Text
:= MyIni.ReadString('Setting','Folder'+inttostr(i),'');
end;
MyIni.Free;
end;
//ListView排序的回调函数,默认的是快速排序法,也可以自己在这里做算法
function CustomSortProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
var txt1,txt2 : string;
begin
if ParamSort <> 0 then
begin
try
txt1 := Item1.SubItems.Strings[ParamSort-1];
txt2 := Item2.SubItems.Strings[ParamSort-1];
if m_bSort then
begin
Result := CompareText(txt1,txt2);
end
else
begin
Result := -CompareText(txt1,txt2);
end;
except
end;
end
else
begin
if m_bSort then
begin
Result := CompareText(Item1.Caption,Item2.Caption);
end
else
begin
Result := -CompareText(Item1.Caption,Item2.Caption);
end;
end;
end;
//单击listview列标题栏排序
procedure TForm1.ListView1ColumnClick(Sender: TObject;
Column: TListColumn);
begin
ListView1.CustomSort(@CustomSortProc, Column.Index);
{//升序图标
if m_bSort = True then
Column.ImageIndex := 0
else
//降序图标
Column.ImageIndex := 1;
}
m_bSort := not m_bSort; //再次单击标题栏倒序排列
end;
procedure TForm1.ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
Data: Integer; var Compare: Integer);
begin
if Data = 0 then //按标题列排序
Compare := CompareStr(Item1.Caption, Item2.Caption)
else //按其他列排序
Compare := CompareStr(Item1.SubItems.Strings[Data-1], Item2.SubItems.Strings[Data-1]);
end;
//listview1失去焦点后仍保持所选项为蓝色状态
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
if Item.Selected then
Sender.Canvas.Brush.Color := clSkyBlue;
end;
//显示程序帮助说明
procedure TForm1.Button4Click(Sender: TObject);
begin
ShowMessage('                   欢迎使用文件整理程序!'+#13#10+#13#10+
'  首次使用本程序请点击“设置”按钮,设定至少一个目标文件夹,然后单击“确定”后重新进入程序。'+#13#10+
'在左侧文件列表框中选择要移动的文件,然后点击右侧下拉目标文件夹列表下箭头处,从中选择目标路径,'+#13#10+
'此时列表下方会显示待移动文件信息,重复此项操作。当需整理文件选择确认无误后,点击下方确定按钮。'+#13#10+
'程序即可自动完成当前所在文件夹的文件整理工作。'+#13#10+#13#10+
'  本程序由陈喆个人编程工作室出品,您在使用中如有不满意之处,请多提出宝贵意见,并及时向本人'+#13#10+
'反馈(邮箱地址:27005658@qq.com),在此仅向您表示诚挚的谢意!');
end;
end.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册