ejla51
asked on
OpenDialog - filtered filelist?
I want to have filtered TOpenDialog filelist matching to preset filename mask.
E.g.
OpenDialog.Filename := filepath + 'MyDocs*' +'*.doc';
OpenDialog.Execute;
...
Only files named initial as "MyDocs..." would be visible in the OpenDialog filelist?
How to do?
E.g.
OpenDialog.Filename := filepath + 'MyDocs*' +'*.doc';
OpenDialog.Execute;
...
Only files named initial as "MyDocs..." would be visible in the OpenDialog filelist?
How to do?
ASKER
This filter have affect only to file extensions, not names.
I want to show filenames, e.g. all files witch match to "MyDoc*.doc'. (MyDoc1, MyDoc2, MyDoc3,etc).
Have tried something as below:
ListFiles(prg.FilePath, 'MyDoc*.doc', OpenDialog1.Files);
// This does not update files in the OpenDialog....
procedure ListFiles(const AFolder, AFilter: string; AList: TStrings);
var
vFindHandle: THandle;
vFilter : String;
vFindData : WIN32_FIND_DATA;
begin
AList.BeginUpdate;
try
AList.Clear;
vFilter := AFolder + '\' + AFilter;
vFindHandle := FindFirstFile(PChar(vFilte r), vFindData);
if vFindHandle = INVALID_HANDLE_VALUE then Exit;
repeat
AList.Add(ChangeFileExt(vF indData.cF ileName, ''));
until not FindNextFile(vFindHandle, vFindData);
Windows.FindClose(vFindHan dle);
finally
AList.EndUpdate;
end;
end;
I want to show filenames, e.g. all files witch match to "MyDoc*.doc'. (MyDoc1, MyDoc2, MyDoc3,etc).
Have tried something as below:
ListFiles(prg.FilePath, 'MyDoc*.doc', OpenDialog1.Files);
// This does not update files in the OpenDialog....
procedure ListFiles(const AFolder, AFilter: string; AList: TStrings);
var
vFindHandle: THandle;
vFilter : String;
vFindData : WIN32_FIND_DATA;
begin
AList.BeginUpdate;
try
AList.Clear;
vFilter := AFolder + '\' + AFilter;
vFindHandle := FindFirstFile(PChar(vFilte
if vFindHandle = INVALID_HANDLE_VALUE then Exit;
repeat
AList.Add(ChangeFileExt(vF
until not FindNextFile(vFindHandle, vFindData);
Windows.FindClose(vFindHan
finally
AList.EndUpdate;
end;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, I agree this works as is... but I have to use a variabel to identify users and allow select only respective users files
us := usr.LoggedUser;
OpenDialog1.Filter := us + ' logs ('+ us + '*.log)|us + *.log';
Seems good, but a still a little problem... This does not work :-(
(Hardcoded filter does work fine)
us := usr.LoggedUser;
OpenDialog1.Filter := us + ' logs ('+ us + '*.log)|us + *.log';
Seems good, but a still a little problem... This does not work :-(
(Hardcoded filter does work fine)
ASKER
Found it ...
us := usr.LoggedUser;
flt := 'Logfiles (' + us + '*.log)|' + us + '*.log';
OpenDialog1.Filter := flt;
Thanks!
us := usr.LoggedUser;
flt := 'Logfiles (' + us + '*.log)|' + us + '*.log';
OpenDialog1.Filter := flt;
Thanks!
Open in new window
... property FileName is for setting destination/source file.