python – Finding the user’s “Downloads” folder
from pathlib import Path downloads_path = str(Path.home() / “Downloads”)
from pathlib import Path downloads_path = str(Path.home() / “Downloads”)
Try: System.Environment.GetEnvironmentVariable(“USERPROFILE”); Edit: If the version of .NET you are using is 4 or above, you can use the Environment.SpecialFolder enumeration: Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
Yes it is special, discovering the name of this folder didn’t become possible until Vista. .NET still needs to support prior operating systems. You can pinvoke SHGetKnownFolderPath() to bypass this limitation, like this: using System.Runtime.InteropServices; … public static string GetDownloadsPath() { if (Environment.OSVersion.Version.Major < 6) throw new NotSupportedException(); IntPtr pathPtr = IntPtr.Zero; try { SHGetKnownFolderPath(ref … Read more
It’s not a “problem”, it’s a feature. It’s called User Account Control (UAC), and it’s one of the ways that system security was tightened under Windows Vista. Windows 7 indeed retains a similar security model. There’s absolutely no reason that your application should need to mess with system folders in the first place. As you’ve … Read more