forked from MGuffin/xTranslator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFolderUtil.pas
More file actions
45 lines (36 loc) · 1.08 KB
/
FolderUtil.pas
File metadata and controls
45 lines (36 loc) · 1.08 KB
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
unit FolderUtil;
interface
type
RFolderHelper = record
strict private
class function GetFolder(const aCSIDL: Integer): string; static;
public
class function GetMyDocumentsFolder: string; static;
class function GetMyMusicFolder: string; static;
// ... any other folders in which you are interested
end;
implementation
uses
ShlObj, // Needed for the CSIDL constants
Windows;
function SHGetFolderPath(hwnd: HWND; csidl: Integer; hToken: THandle;
dwFlags: DWord; pszPath: LPWSTR): HRESULT; stdcall;
forward;
function SHGetFolderPath; external 'SHFolder.dll' name 'SHGetFolderPathW';
class function RFolderHelper.GetFolder(const aCSIDL: Integer): string;
var
FolderPath: array[0 .. MAX_PATH] of Char;
begin
SetLastError(ERROR_SUCCESS);
if SHGetFolderPath(0, aCSIDL, 0, 0, @FolderPath) = S_OK then
Result := FolderPath;
end;
class function RFolderHelper.GetMyDocumentsFolder: string;
begin
Result := GetFolder(CSIDL_PERSONAL);
end;
class function RFolderHelper.GetMyMusicFolder: string;
begin
Result := GetFolder(CSIDL_MYMUSIC);
end;
end.