mundodelphi

programacion en delphi

Obtener path de los directorios de windows

Con ese truco podemos obtener los directorios de windows usando delphi

La función es FM_GetSpecialDirectory(directorio:string):string;
se debe cargar en uses la librería ShlObj

Parametros del atributo directorio

AppData
CdBurn
AdminTools
Cookies
StartMenu
Desktop
Favorites
Fonts
History
InternetCache
LocalAppData
MyMusic
MyImages
Metwork
MyDocuments
Printers
User
Programs
Shared
Sendto
Starmenu
Starmenuprog
System
Windows
Temp

Código

Uses ShlObj;
Function FM_GetSpecialDirectory(const directorio : string) : string;
var RecPath : PAnsiChar;
 CSIDL:integer;
begin
 if ansilowercase(directorio) = 'appdata' then  CSIDL := $001a;
 if ansilowercase(directorio) = 'cdburn' then  CSIDL := $003b;
 if ansilowercase(directorio) = 'admintools' then  CSIDL := $002f;
 if ansilowercase(directorio) = 'cookies' then  CSIDL := $0021;
 if ansilowercase(directorio) = 'startmenu' then  CSIDL := $0000;
 if ansilowercase(directorio) = 'desktop' then  CSIDL := $0010;
 if ansilowercase(directorio) = 'favorites' then  CSIDL := $0006;
 if ansilowercase(directorio) = 'fonts' then  CSIDL := $0014;
 if ansilowercase(directorio) = 'history' then  CSIDL := $0022;
 if ansilowercase(directorio) = 'internetcache' then  CSIDL := $0020;
 if ansilowercase(directorio) = 'localappdata' then  CSIDL := $001c;
 if ansilowercase(directorio) = 'mymusic' then  CSIDL := $000d;
 if ansilowercase(directorio) = 'myimages' then  CSIDL := $0027;
 if ansilowercase(directorio) = 'network' then  CSIDL := $0013;
 if ansilowercase(directorio) = 'mydocuments' then  CSIDL := $0005;
 if ansilowercase(directorio) = 'printers' then  CSIDL := $001b;
 if ansilowercase(directorio) = 'user' then  CSIDL := $0028;
 if ansilowercase(directorio) = 'programs' then  CSIDL := $0026;
 if ansilowercase(directorio) = 'shared' then  CSIDL := $002b;
 if ansilowercase(directorio) = 'recent' then  CSIDL := $0008;
 if ansilowercase(directorio) = 'sendto' then  CSIDL := $0009;
 if ansilowercase(directorio) = 'starmenu' then  CSIDL := $000b;
 if ansilowercase(directorio) = 'starmenuprog' then  CSIDL := $0007;
 if ansilowercase(directorio) = 'system' then  CSIDL := $0025;
 if ansilowercase(directorio) = 'windows' then  CSIDL := $0024;
 if ansilowercase(directorio) = 'temp' then  CSIDL := $0024;

 RecPath := StrAlloc(MAX_PATH);
 try
 FillChar(RecPath^,MAX_PATH,0);
 if SHGetSpecialFolderPath(0,RecPath,CSIDL,false) then begin
 result := RecPath;
 if ansilowercase(directori) = 'temp' then result := RecPath + '\temp';
 end else result := '';
 finally
 StrDispose(RecPath);
 end;
end;

su uso es muy fácil
FM_GetSpecialDirectory(‘windows’);

con eso obtenemos el directorio donde windows está instalado C:\windows en mi caso

Tagged as: ,

Leave a Response

Please note: comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Google Analytics Alternative