Desktop folder lazarus / 61-Beginners ---------------------------------------------------------------------- Petrus Vorster · 2024-09-05 08:29 Hi All How do I get the Desktop folder in windows? I need to drop the CSV file on the desktop for the user. (preferably without the user action or selections.) I have gone through a lot of searches on the forum, but there are a lot of answers that I currently know nothing off. Thank you for all your help. It is much appreciated. -Peter ---------------------------------------------------------------------- ASerge · 2024-09-05 08:34 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses WinDirs; procedure TForm1.Button1Click(Sender: TObject);begin  Caption := GetWindowsSpecialDir(CSIDL_DESKTOPDIRECTORY);end; ---------------------------------------------------------------------- Petrus Vorster · 2024-09-05 08:35 That's it??? WOW. Thanks mate. -Peter ---------------------------------------------------------------------- Zvoni · 2024-09-05 08:40 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1;Uses Sysutils;begin  writeln(GetUserDir);end. .... and just append "\Desktop" to it Note: This goes Kaboom in case of OneDrive (like on my company laptop. My "Desktop" is within OneDrive, so.....) If it'S OneDrive-Based, you first have to check, if OneDrive is installed (in AppData IIRC), and then build the final Path-String As a final Sanity-Check use "DirectoryExists" beofre dropping the File on the Desktop EDIT: AAHA.... Thx Serge. Didn't know that one. EDIT2: YAY! Serge's Solution works even with OneDrive-based Folders ---------------------------------------------------------------------- eny · 2024-09-05 19:10 Quote from: Zvoni on September 05, 2024, 10:40:19 am.... and just append "\Desktop" to itThis also does Kaboom for non-English versions of Window$ ---------------------------------------------------------------------- Remy Lebeau · 2024-09-05 19:24 Quote from: Zvoni on September 05, 2024, 10:40:19 amCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1;Uses Sysutils;begin  writeln(GetUserDir);end. .... and just append "\Desktop" to it DO NOT do that.  That is not guaranteed to be the correct path on every version of every system.  Shell folders can be renamed (localization, etc), relocated by the user, mapped by the system (OneDrive, etc), and so on.  Windows knows the exact and correct path, so ask Windows where it actually is.  Same with ANY system-managed path.  NEVER create system paths manually. ---------------------------------------------------------------------- dbannon · 2024-09-06 02:22 Hmm, thats interesting, I do this - Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i         {$ifdef WINDOWS}        TheHomeDir := appendPathDelim(GetEnvironmentVariableUTF8('HOMEPATH')); And assume Desktop is immediately below that. Is that not a safe practice ? Davo ---------------------------------------------------------------------- dsiders · 2024-09-06 02:48 Quote from: dbannon on September 06, 2024, 04:22:13 amHmm, thats interesting, I do this - Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i         {$ifdef WINDOWS}        TheHomeDir := appendPathDelim(GetEnvironmentVariableUTF8('HOMEPATH')); And assume Desktop is immediately below that. Is that not a safe practice ? Davo I think you need the combined values of HOMEDRIVE and HOMEPATH on Windows. ---------------------------------------------------------------------- Zvoni · 2024-09-06 06:23 Quote from: dbannon on September 06, 2024, 04:22:13 amHmm, thats interesting, I do this - Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i         {$ifdef WINDOWS}        TheHomeDir := appendPathDelim(GetEnvironmentVariableUTF8('HOMEPATH')); And assume Desktop is immediately below that. Is that not a safe practice ? Davo No it's not. Exactly because of the reasons Remy described. On my company-laptop my "Desktop" is on a OneDrive, which is NOT directly below HOMEPATH ---------------------------------------------------------------------- dbannon · 2024-09-06 12:05 Hmm, OK, sounds like I had better fix that before next release. I have not had any complaints and about  2/3 of my users seem to be on Windows. But I can understand its wrong ! Thanks for thee heads up ! Davo