-
Notifications
You must be signed in to change notification settings - Fork 5
/
SelectFilesOnExplorer.dpr
78 lines (61 loc) · 1.55 KB
/
SelectFilesOnExplorer.dpr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Jean-Pierre LESUEUR (@DarkCoderSc)
// https://keybase.io/phrozen
program SelectFilesOnExplorer;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
System.Classes,
Winapi.Windows,
Winapi.ActiveX,
Winapi.ShlObj;
{ _.ShowFilesOnExplorer }
procedure ShowFilesOnExplorer(const ADirectory : String; const AStringList : TStringList);
var AList : array of PItemIDList;
pDir : PItemIDList;
AFile : String;
I : Cardinal;
begin
if not Assigned(AStringList) then
Exit();
///
SetLength(AList, AStringList.Count);
for I := 0 to AStringList.count -1 do begin
AFile := IncludeTrailingPathDelimiter(ADirectory) + AStringList.Strings[I];
if not FileExists(AFile) then
continue;
AList[I] := ILCreateFromPath(PWideChar(AFile));
end;
pDir := ILCreateFromPath(PWideChar(ADirectory));
SHOpenFolderAndSelectItems(pDir, Length(AList), PItemIDList(AList), 0);
for I := 0 to Length(AList) -1 do begin
if Assigned(AList[I]) then
ILFree(AList[I]);
end;
ILFree(pDir);
end;
// Usage example
var AFiles : TStringList;
begin
try
CoInitialize(nil); // Important
try
AFiles := TStringList.Create();
try
AFiles.Add('explorer.exe');
AFiles.Add('notepad.exe');
AFiles.Add('HelpPane.exe');
///
ShowFilesOnExplorer('C:\Windows\', AFiles);
finally
if Assigned(AFiles) then
FreeAndNil(AFiles);
end;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
finally
CoUninitialize();
end;
end.