if i try getting with GetOptionValue('f', 'file') i get only first filename, if GetOptionValues('f', 'file') i get array with first filename too..
Makes sense, because the Shell is expanding the wildcard before the parameters are sent to your app. So GetOptionValue/s have no idea that a wildcard was ever used, they are just pulling whatever the next parameter is after '-f'.
How i can get all filelist or full wildcard *.txt (for search files in code later)?
Use
ParamStr() directly. Loop through
ParamCount(), and when you encounter the
'-f' parameter then look at the
next parameter. If it has a wildcard then the Shell didn't expand it so you can use that parameter value with
FindFirst/Next() (or equivalent) to loop through the file paths yourself. Otherwise, the Shell did expand the wildcard (or no wildcard was provided) so look at all of the parameters following
'-f' until you reach the next option or the parameter list is exhausted.
For example, something like this:
count := ParamCount;
files := TStringList.Create;
x := 1;
while x <= count do
begin
...
param := ParamStr(x); Inc(x);
if param = '-f' then
begin
param := ParamStr(x); Inc(x);
if (Pos('*', param) <> 0) or (Pos('?', param) <> 0) then
begin
folder := IncludeTrailingPathDelimiter(ExtractFilePath(param));
if FindFirst(param, faAnyFile, sr) = 0 then
try
repeat
if (sr.Name <> '.') and (sr.Name <> '..') and ((sr.Attr and faDirectory) = 0) then
files.Add(folder + sr.Name);
until FindNext(sr) = 0;
finally
FindClose(sr);
end;
end else
begin
files.Add(param);
while x <= count do
begin
param := ParamStr(x);
if param[1] = '-' then Break;
files.Add(param);
Inc(x);
end;
end;
end
...
end;
// use files as needed...
files.Free;