I can't delete a folder using %userprofile% lazarus / 21-General ---------------------------------------------------------------------- AnthonyStuart · 2021-01-05 16:57 Hi, I'm Anthony. And I have a project which is to create a cleaning software, like Ccleaner, I have used the DeleteDirectory function. The problem is that I want to delete for example the history of microsoft edge, the data is in, AppData / Local / Microsoft / Edge / Default folder, what I want to do is that when I make it delete, look for the user's folder , not mine, that's why I use %userprofile%, but when using it, it doesn't find the file. Another thing, how can I delete an individual file? I am new, and Free Pascal, I found it very easy to understand and use. Greetings to all!... ---------------------------------------------------------------------- marcov · 2021-01-05 17:05 Most FPC functions are programmer interface functions, not windows explorer functions. These are faster, but don't do things like environment variable expansion. IOW you need to expand these yourself, using getenvironmentstring() or getwindowsspecialdir and string operations. ---------------------------------------------------------------------- Handoko · 2021-01-05 17:13 @AnthonyStuart, As I do not use Windows, not much I can say about it. Have you tried to browse to the location and delete those files or folder using your File Manager or Windows Explorer? If cannot find or deletem them, maybe they have file attribute set to hidden or maybe permission issue. As far as I know, Win10 does not allow user to access certain data of other users. You may need to set the file attribut to include hidden and/or system file: https://www.freepascal.org/docs-html/rtl/sysutils/findfirst.html Quote from: AnthonyStuart on January 05, 2021, 05:57:21 pm... how can I delete an individual file? You can use DeleteFile: https://www.freepascal.org/docs-html/rtl/sysutils/deletefile.html ---------------------------------------------------------------------- Remy Lebeau · 2021-01-05 20:59 Quote from: marcov on January 05, 2021, 06:05:15 pmIOW you need to expand these yourself, using getenvironmentstring() or getwindowsspecialdir and string operations. GetEnvironmentString() won't work in this case, as there is no environment variable defined for the local AppData folder, only for the roaming AppData folder. As for GetWindowsSpecialDir(), there are no CSIDL (or even a KNOWNFOLDERID) defined for any of Microsoft Edge's folders.  But, you can use GetWindowsSpecialDir(CSIDL_LOCAL_APPDATA, False) and then append '\Microsoft\Edge\Default' to the result of that. ---------------------------------------------------------------------- jamie · 2021-01-05 21:59 Has anyone looked at "ExpandEnvironmentStrs" ? ---------------------------------------------------------------------- Remy Lebeau · 2021-01-05 22:37 Quote from: jamie on January 05, 2021, 10:59:17 pmHas anyone looked at "ExpandEnvironmentStrs" ? That is just a wrapper for the Win32 ExpandEnvironmentStrings() function in kernel32.dll.  That has the same problem that GetEnvironmentString() has - there are no environment variables defined for the file path that Anthony is looking for. ---------------------------------------------------------------------- AnthonyStuart · 2021-01-05 23:35 at least I can make it run a .bat with the command but not even that xD that is, it does not work, at least I put the full path, but if I want to share it it will not work ---------------------------------------------------------------------- lucamar · 2021-01-06 04:46 Quote from: AnthonyStuart on January 06, 2021, 12:35:08 amthat is, it does not work, at least I put the full path, but if I want to share it it will not work You've to tell us what doesn't work and show us what code you tried. Otherwise it's all crystal-balling, which doesn't usually work very well But OK, normally you would use GetUserDir() to get the "base" directory and add the relative path to it, which for your needs would be something like: 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 function GetEdgeDataDir: String;const  RelPath = 'AppData\Local\Microsoft\Edge\Default';begin  Result := GetUserDir + RelPath;end; If that fails, make sure the function's result is shown somewhere (like in a ShowMessage() or a StatusBar) and then check to see whether: the directory exist andthe user has enough permissions to do whatever the program is trying.[/tt]).(both of which you should be doing anyway before anything else ...) And that's basically all there is to it ---------------------------------------------------------------------- Remy Lebeau · 2021-01-06 18:47 Quote from: lucamar on January 06, 2021, 05:46:22 amBut OK, normally you would use GetUserDir() to get the "base" directory and add the relative path to it That would be the wrong solution in this case, since the user can configure Windows to relocate the AppData folder to wherever they want.  So it is not quaranteed to be underneath their user profile.  That is why the Win32 API provides a way to get the exact location of the AppData folder, as described earlier, eg: 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 function GetEdgeDataDir: String;begin  Result := GetWindowsSpecialDir(CSIDL_LOCAL_APPDATA, False);  if Result <> '' then    Result := IncludeTrailingPathDelimiter(Result) + 'Microsoft\Edge\Default';end; ---------------------------------------------------------------------- lucamar · 2021-01-06 19:52 Quote from: Remy Lebeau on January 06, 2021, 07:47:46 pmThat would be the wrong solution in this case, since the user can configure Windows to relocate the AppData folder to wherever they want. Which is why I wrote "normally" (i.e. for users who don't mess too much with the innards of Windows) and insisted on the necessity of checking tht it went well. But you're right: yours is a better solution