4 个解决方案
#1
用samples里面的控件 ShellListView
#2
在ShellListView里面怎样禁止用户打开一个文件夹?也就是只能选择,不能通过双击进行打开?
#3
也可以用ListView!先获得文件列表,用什么方法?
FindFirst,FindNext,这种代码很容易写吧?
不过我喜欢用FileListBox控件,然后...
var
PicFileSize,PFile,i:integer;
FSize,FDateTime:String;
LV:TListItem;
begin
For i:=1 to FileListBox.Items.Count do
begin
try
if DirPath<>SV.Directory then Break;
LV:=ListView.Items.Add;
LV.Caption:=FileListBox.Items.Strings[i-1];
LV.ImageIndex:=GetFileIcoIndex(FileListBox.Items.Strings[i-1]);
Repeat
PFile:=FileOpen(FileListBox.Items.Strings[i-1], fmOpenRead);
until PFile<>-1;
FDateTime:=DateTimeToStr(FileDateToDateTime(FileGetDate(PFile)));
PicFileSize:=FileSeek(PFile,0,2);
FileClose(PFile);
if PicFileSize<1024 then
FSize:=inttostr(PicFileSize)+' 字节'
else if PicFileSize<1048576 then
FSize:=floattostr(Trunc(PicFileSize/102.4)/10)+' KB'
else
FSize:=floattostr(Trunc(PicFileSize/104857.6)/10)+' MB';
LV.SubItems.Add(FSize);
LV.SubItems.Add(FDateTime);
except
Continue;
end;
Application.ProcessMessages;
end;
end;
FindFirst,FindNext,这种代码很容易写吧?
不过我喜欢用FileListBox控件,然后...
var
PicFileSize,PFile,i:integer;
FSize,FDateTime:String;
LV:TListItem;
begin
For i:=1 to FileListBox.Items.Count do
begin
try
if DirPath<>SV.Directory then Break;
LV:=ListView.Items.Add;
LV.Caption:=FileListBox.Items.Strings[i-1];
LV.ImageIndex:=GetFileIcoIndex(FileListBox.Items.Strings[i-1]);
Repeat
PFile:=FileOpen(FileListBox.Items.Strings[i-1], fmOpenRead);
until PFile<>-1;
FDateTime:=DateTimeToStr(FileDateToDateTime(FileGetDate(PFile)));
PicFileSize:=FileSeek(PFile,0,2);
FileClose(PFile);
if PicFileSize<1024 then
FSize:=inttostr(PicFileSize)+' 字节'
else if PicFileSize<1048576 then
FSize:=floattostr(Trunc(PicFileSize/102.4)/10)+' KB'
else
FSize:=floattostr(Trunc(PicFileSize/104857.6)/10)+' MB';
LV.SubItems.Add(FSize);
LV.SubItems.Add(FDateTime);
except
Continue;
end;
Application.ProcessMessages;
end;
end;
#4
错了!如果要包括目录就只能用我的第一种方法获得列表!
#1
用samples里面的控件 ShellListView
#2
在ShellListView里面怎样禁止用户打开一个文件夹?也就是只能选择,不能通过双击进行打开?
#3
也可以用ListView!先获得文件列表,用什么方法?
FindFirst,FindNext,这种代码很容易写吧?
不过我喜欢用FileListBox控件,然后...
var
PicFileSize,PFile,i:integer;
FSize,FDateTime:String;
LV:TListItem;
begin
For i:=1 to FileListBox.Items.Count do
begin
try
if DirPath<>SV.Directory then Break;
LV:=ListView.Items.Add;
LV.Caption:=FileListBox.Items.Strings[i-1];
LV.ImageIndex:=GetFileIcoIndex(FileListBox.Items.Strings[i-1]);
Repeat
PFile:=FileOpen(FileListBox.Items.Strings[i-1], fmOpenRead);
until PFile<>-1;
FDateTime:=DateTimeToStr(FileDateToDateTime(FileGetDate(PFile)));
PicFileSize:=FileSeek(PFile,0,2);
FileClose(PFile);
if PicFileSize<1024 then
FSize:=inttostr(PicFileSize)+' 字节'
else if PicFileSize<1048576 then
FSize:=floattostr(Trunc(PicFileSize/102.4)/10)+' KB'
else
FSize:=floattostr(Trunc(PicFileSize/104857.6)/10)+' MB';
LV.SubItems.Add(FSize);
LV.SubItems.Add(FDateTime);
except
Continue;
end;
Application.ProcessMessages;
end;
end;
FindFirst,FindNext,这种代码很容易写吧?
不过我喜欢用FileListBox控件,然后...
var
PicFileSize,PFile,i:integer;
FSize,FDateTime:String;
LV:TListItem;
begin
For i:=1 to FileListBox.Items.Count do
begin
try
if DirPath<>SV.Directory then Break;
LV:=ListView.Items.Add;
LV.Caption:=FileListBox.Items.Strings[i-1];
LV.ImageIndex:=GetFileIcoIndex(FileListBox.Items.Strings[i-1]);
Repeat
PFile:=FileOpen(FileListBox.Items.Strings[i-1], fmOpenRead);
until PFile<>-1;
FDateTime:=DateTimeToStr(FileDateToDateTime(FileGetDate(PFile)));
PicFileSize:=FileSeek(PFile,0,2);
FileClose(PFile);
if PicFileSize<1024 then
FSize:=inttostr(PicFileSize)+' 字节'
else if PicFileSize<1048576 then
FSize:=floattostr(Trunc(PicFileSize/102.4)/10)+' KB'
else
FSize:=floattostr(Trunc(PicFileSize/104857.6)/10)+' MB';
LV.SubItems.Add(FSize);
LV.SubItems.Add(FDateTime);
except
Continue;
end;
Application.ProcessMessages;
end;
end;
#4
错了!如果要包括目录就只能用我的第一种方法获得列表!