Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
||
ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
[18.191.74.239] |
|
Страницы: (2) [1] 2 все ( Перейти к последнему сообщению ) |
Сообщ.
#1
,
|
|
|
В вашем FAQ есть способ нахождения временной папки Windows:
function c_GetTempPath: String; var Buffer: array[0..1023] of Char; begin SetString(Result, Buffer, GetTempPath(Sizeof(Buffer)-1,Buffer)); end; Но возвращаемое значение (у меня) получается таким: C:\DOCUME~1\071A~1\LOCALS~1\Temp. Как получить нормальный полный вид строки, вроде: C:\Documents and Settings\User2\Local Settings\Temp ? |
Сообщ.
#2
,
|
|
|
GetFullPathName ?
|
Сообщ.
#3
,
|
|
|
А как ей пользоваться? Нигде её описания не нашёл.
|
Сообщ.
#4
,
|
|
|
что значит не нашёл ? да она где хочешь есть
Цитата DWORD GetFullPathName( LPCTSTR lpFileName, // address of name of file to find path for DWORD nBufferLength, // size, in characters, of path buffer LPTSTR lpBuffer, // address of path buffer LPTSTR *lpFilePart // address of filename in path ); Parameters lpFileName Points to a null-terminated string that specifies a valid filename. This string can use either short (the 8.3 form) or long filenames. nBufferLength Specifies the size, in characters, of the buffer for the drive and path. lpBuffer Points to a buffer that contains the null-terminated string for the name of the drive and path. lpFilePart Points to a variable that receives the address (in lpBuffer) of the final filename component in the path. This filename component is the long filename, if any, rather than the 8.3 form of the filename. Return Values If the GetFullPathName function succeeds, the return value is the length, in characters, of the string copied to lpBuffer, not including the terminating null character. If the lpBuffer buffer is too small, the return value is the size of the buffer, in characters, required to hold the path. If the function fails, the return value is zero. To get extended error information, call GetLastError. |
Сообщ.
#5
,
|
|
|
Можешь на примере показать. У меня вылетает ошибка где указывается библиотека 'ntdll.dll'
|
Сообщ.
#6
,
|
|
|
Buffer : array[0..254] of Char; FullName,ShortName : PChar; ... GetFullPathName(ShortName,255, buffer, Fullname); Нашёл еще через FindFirst прикольный способ. function GetLongFileName(InputName: string): string; var Root, Net: Boolean; InPath, CurP, BegP: PChar; CurItem, CurPath, OutPath: string; RootGuard: SmallInt; FindHandle: Cardinal; FindData: WIN32_FIND_DATA; begin OutPath:= InputName; InPath:= PChar(InputName); Root:= True; Net:= False; RootGuard:= 0; CurP:= InPath; while CurP^<>#0 do begin BegP:= CurP; while (CurP^<>'\') and (CurP^<>#0) do CurP := CharNext(CurP); SetString(CurItem, BegP, CurP - BegP); if CurItem='' then CurPath:= CurPath+'\' else begin CurPath:= CurPath+CurItem; if Root then begin OutPath:= CurPath; CurPath:= CurPath+'\'; end;{if Root then} end;{if CurItem='' then CurPath:= CurPath+'\' else} if (CurPath='\\') or (CurPath='\') then Net:= True; if Root then begin if Net then begin RootGuard:= -1; Net:= False; end;{if Net then} Inc(RootGuard); if RootGuard>0 then Root:= False; end{if Root then} else begin FindHandle:= FindFirstFile(PChar(CurPath), FindData); OutPath:= OutPath+'\'+FindData.cFileName; Windows.FindClose(FindHandle); CurPath:= CurPath+'\'; end;{if Root then ... else} CurP := CharNext(CurP); end;{while CurP^ <> #0 do} Result:= OutPath; end;{GetLongFileName} ... теперь твой темп : showmessage(GetLongFileName(c_GetTempPath)); |
Сообщ.
#7
,
|
|
|
У меня есть специальный для этого компонент Dir B) для определения системных папок Windows если надо то пиши вышлю [EMAIL]bartram@narod.ru[/EMAIL]
|
Сообщ.
#8
,
|
|
|
То что тебе надо. Проверено, вирусов нет!
function GetTempPathLong: string; Uses ShlObj,Comobj,ActiveX; var Desktop: IShellFolder; pIDList: PITEMIDLIST; NameS: String; NameW: WideString; Len : integer; Buffer: array[0..MAX_PATH] of Char; pDummy: PCHAR; pchEaten, Attributes: ULONG; shortname:string; function c_GetTempPath: string; var Buffer: array[0..1023] of Char; begin SetString(Result, Buffer, GetTempPath(Sizeof(Buffer) - 1, Buffer)); end; begin ShortName:=c_GetTempPath; pIDList := Nil; Len := GetFullPathName(PChar(ShortName), 0, PChar(result), pDummy); SetLength(NameS, Len); GetFullPathName(PChar(ShortName), Len, PChar(NameS), pDummy); NameW := NameS; OleCheck(SHGetDesktopFolder(Desktop)); OleCheck(Desktop.ParseDisplayName(0, Nil, PWideChar(NameW), pchEaten, pIDList, Attributes)); SHGetPathFromIDList(pIDList, Buffer); Result := StrPas(Buffer); end; |
Сообщ.
#9
,
|
|
|
ExpandFileName
|
Сообщ.
#10
,
|
|
|
Цитата Rouse_ @ ExpandFileName не пашет. |
Сообщ.
#11
,
|
|
|
Мдя, действительно, ну тогда вот так:
type function GetLongPathNameA(lpszShortPath, lpszLongPath: PChar; cchBuffer: DWORD): DWORD; stdcall external kernel32; ... procedure TForm1.Button2Click(Sender: TObject); var ShortPath, LongPath: array[0..MAX_PATH - 1] of Char; begin if GetTempPath(MAX_PATH, @ShortPath[0]) > 0 then if GetLongPathNameA(ShortPath, @LongPath[0], MAX_PATH) > 0 then ShowMessage(String(LongPath)); end; |
Сообщ.
#12
,
|
|
|
Цитата Rouse_ @ ну тогда вот так клево, respect!!! |
Сообщ.
#13
,
|
|
|
Я.. Дико извиняюсь, но до сегодня под d2007 меня вполне устраивал такой способ:
function GetTempDir: String; //При помощи данной функции на Delphi можно узнать путь к папке для временных файлов в операционной системе Windows. var Buf: array[0..1023] of Char; begin SetString(Result, Buf, GetTempPath(Sizeof(Buf)-1,Buf)); end; А вот при вызове этой функции в D2009 получаем acces violation. Подскажите плз как быть? Добавлено удовлетворился решением отсюда : Get Windows Temp directory thePath holds the Windows Temp directory: ~~~~~~~~~~~~~~~~~~~~~~~~~ var lng: DWORD; thePath: string; begin SetLength(thePath, MAX_PATH) ; lng := GetTempPath(MAX_PATH, PChar(thePath)) ; SetLength(thePath, lng) ; end; Работает в D2009 и выдает нормальный путь без "~" |
Сообщ.
#14
,
|
|
|
НО,этот способ не возвращает путь в VISTA, если программа запущена из-под ограниченного пользователя
Подскажите плз, как побороть ? |
Сообщ.
#15
,
|
|
|
Цитата Erazer @ А вот при вызове этой функции в D2009 получаем acces violation. Подскажите плз как быть? А что, разве вы не в курсе, что в D2009 теперь unicode по-умолчанию? По-моему об этом теперь уже даже дети знают, так громко об этом кричали. Ну и включите ненадолго свою голову и подумайте, где накосячили. Я вам даже подскажу, что первый параметр у GetTempPath это: Цитата The size of the string buffer identified by lpBuffer, in TCHARs. А вы что ему пихаете? Цитата Erazer @ НО,этот способ не возвращает путь в VISTA, если программа запущена из-под ограниченного пользователя Подскажите плз, как побороть ? Работает он, работает. И для гостя и для админа. Проверяйте, где угробили настройки системы. Попробуйте посмотреть GetEnvironmentVariable('TEMP'); или 'TMP' P.S. Кстати, у меня есть подозрение, что эти функции всегда возвращают короткий путь. Просто иногда короткий путь совпадает с длинным. Но я это не проверял. |