悲
悲酥清风
Unregistered / Unconfirmed
GUEST, unregistred user!
我写了段代码查找子目录下的文件,可是返回的总是空。请大虾帮我看看。
代码如下
procedure TForm1.Button1Click(Sender: TObject);
var
Reg: TRegistry;
FavorPath: string
//save the path of Favorites folder
SubDir1: TStrings
//save the sub dir of Favorites folder
SearchRec: TSearchRec;
i: integer;
begin
SubDir1:= TStringList.Create;
Reg:= TRegistry.Create;
//SearchRec:= TSearchRec.Create;
{*********read the path of favorites folder*********}
with reg do
begin
RootKey:= HKEY_USERS;
if OpenKey('.DEFAULT/Software/Microsoft/Windows/CurrentVersion/Explorer/User Shell Folders',false) then
FavorPath:= ReadString('Favorites')+'/';
CloseKey;
Free;
end;
{*********find URL files in favorites folder*********}
//first find all files in favorites folder
if (FindFirst(FavorPath+'*.url',faAnyFile,SearchRec)= 0) then
begin
Memo1.Lines.Add(SearchRec.Name);
while FindNext(SearchRec)= 0 do
Memo1.Lines.Add(SearchRec.Name);
end;
//then find all subdir in favirites folder
if (FindFirst(FavorPath+'*.*',faDirectory,SearchRec)= 0) then
begin
SubDir1.Add(SearchRec.Name);
while FindNext(SearchRec)= 0 do
SubDir1.Add(SearchRec.Name);
end;
//find all file in all subdir
for i:= 0 to SubDir1.Count- 1 do
begin
if (FindFirst(FavorPath+SubDir1.Strings+'/*.url',faAnyFile,SearchRec)= 0) then
begin
Memo1.Lines.Add(SearchRec.Name);
while FindNext(SearchRec)= 0 do
Memo1.Lines.Add(SearchRec.Name);
end;
end;
FindClose(SearchRec);
if (Memo1.Lines.Count= 0) then
MessageBox(Handle,'Sorry!'+#13+'You favorites folder have no files.','Warning!',mb_ok);
SubDir1.Free;
end;
代码如下
procedure TForm1.Button1Click(Sender: TObject);
var
Reg: TRegistry;
FavorPath: string
//save the path of Favorites folder
SubDir1: TStrings
//save the sub dir of Favorites folder
SearchRec: TSearchRec;
i: integer;
begin
SubDir1:= TStringList.Create;
Reg:= TRegistry.Create;
//SearchRec:= TSearchRec.Create;
{*********read the path of favorites folder*********}
with reg do
begin
RootKey:= HKEY_USERS;
if OpenKey('.DEFAULT/Software/Microsoft/Windows/CurrentVersion/Explorer/User Shell Folders',false) then
FavorPath:= ReadString('Favorites')+'/';
CloseKey;
Free;
end;
{*********find URL files in favorites folder*********}
//first find all files in favorites folder
if (FindFirst(FavorPath+'*.url',faAnyFile,SearchRec)= 0) then
begin
Memo1.Lines.Add(SearchRec.Name);
while FindNext(SearchRec)= 0 do
Memo1.Lines.Add(SearchRec.Name);
end;
//then find all subdir in favirites folder
if (FindFirst(FavorPath+'*.*',faDirectory,SearchRec)= 0) then
begin
SubDir1.Add(SearchRec.Name);
while FindNext(SearchRec)= 0 do
SubDir1.Add(SearchRec.Name);
end;
//find all file in all subdir
for i:= 0 to SubDir1.Count- 1 do
begin
if (FindFirst(FavorPath+SubDir1.Strings+'/*.url',faAnyFile,SearchRec)= 0) then
begin
Memo1.Lines.Add(SearchRec.Name);
while FindNext(SearchRec)= 0 do
Memo1.Lines.Add(SearchRec.Name);
end;
end;
FindClose(SearchRec);
if (Memo1.Lines.Count= 0) then
MessageBox(Handle,'Sorry!'+#13+'You favorites folder have no files.','Warning!',mb_ok);
SubDir1.Free;
end;