Forum > Operating Systems
[Solved] Get user pictures directory name in Windows and Linux
artem101:
What is cross-platform way to get user pictures dir on Windows and Linux? Like "C:\Documents and Settings\user\My Documents\My Pictures" in Windows XP, "C:\Users\user\Pictures" in Windows 7 and later, "/home/user/Pictures" in Linux.
MarkMLl:
I can't speak for Windows, but in the case of Linux you're entirely at the mercy of the selected distro and the window manager (desktop environment etc.) that you're currently running.
Refer to xdg-user-dir and related xdg utilities as shown by the apropos command, but note that support might be patchy and might be completely missing on a system set up as a server.
MarkMLl
KodeZwerg:
for windows:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses ... shfolder .... ... function GetSpecialFolder(const CSIDL: Integer): string;var i: Integer;begin SetLength(Result, MAX_PATH); ShGetFolderPath(0, CSIDL, 0, 0, PChar(Result)); i := Pos(#0, Result); if (i > 0) then SetLength(Result, pred(i));end; ... var s: string;begin s := GetSpecialFolder(CSIDL_MYPICTURES); ...
Josh:
windows only
uses windirs;
var s:unicodestring;
begin
s:=GetWindowsSpecialDirUnicode(CSIDL_MYPICTURES);
end;
Kays:
Are there any real-life users out there who actually used the pre-created directories “My Pictures” etc. in their intended way? It was the first thing I deleted.
--- Quote from: artem101 on September 10, 2022, 10:21:15 am ---What is cross-platform way to get user pictures dir on Windows and Linux? […]
--- End quote ---
Frankly, I would treat the notion of “special” directories as nonexistent. Only that is cross-platform.
--- Quote from: MarkMLl on September 10, 2022, 10:53:54 am ---[…] Refer to xdg-user-dir and related xdg utilities as shown by the apropos command, but note that support might be patchy and might be completely missing on a system set up as a server. […]
--- End quote ---
The XDG utilities are at least mentioned in the Linux Standard Base. However, xdg‑user‑dir(1) is not a mandatory utility, therefore it may be missing on the specific machine. Not worth mentioning, there are/were hardly any distros fully supporting the LSB, so your statement “at the mercy of the selected distro” is quite accurate.
Navigation
[0] Message Index
[#] Next page