Is there a difference between %USERPROFILE%\Desktop and %SYSTEMDRIVE%%HOMEPATH%\Desktop\ that the path would be correct on Windows versions from Windows XP? I saw somewhere that there are 2 desktop folders on a computer, one Desktop and the other Рабочий стол . And they are different, one is empty and the other is not. What does it mean? How to correctly specify the path to the desktop, regardless of the OS version and other things?

While getting the path System.getenv("USERPROFILE") . It turns out C:\Users\User . I do not know whether it will work everywhere.

I wrote it like this, since in Windows XP, on which I just checked the folder was called Рабочий стол

 Path ADRESS = Paths.get(System.getenv("USERPROFILE") + "\\Desktop"); if(Files.exists(ADRESS)) { \\ } ADRESS = Paths.get(System.getenv("USERPROFILE") + "\\Рабочий стол"); if(Files.exists(ADRESS)) { \\ } 
  • The second option is definitely wrong, since theoretically the desktop may not be located on the system disk. - Yaant
  • @Yaant Yes, I understand - aaa
  • The desktop may be missing in both ways, tested in Windows XP - andreymal
  • @andreymal Can you explain then? - aaa
  • And I myself do not know how to, I am a simple user, I just warned) - andreymal

2 answers 2

%USERPROFILE%\Desktop - will bring the user to the user's desktop folder with a 90% probability, because home users rarely change the default settings and generally guess their existence.

The value of the system variable %USERPROFILE% contains an absolute path (includes the drive letter and all intermediate folders) to the user profile folder, and is set by the operating system (it is strongly recommended not to change hands).

%Public%\Desktop\ - will output to the common desktop folder for all users.

The default folder name is always Desktop . The localized name is set using the settings in the hidden desktop.ini and is simply a synonym.

Desktop folder, like almost all folders like Documents , Favorites , etc. can be redirected to an arbitrary place, including network resources, using group policies, or manually configured by the user. In this case, %USERPROFILE%\Desktop returns the wrong path, and even if there is a corresponding folder there, the user will not see the files added to it on his desktop.

In this case, to get the current path to the user's desktop, you can use the registry.

We need a branch:
"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
and in it the Desktop key, the value of which contains the absolute path to the current desktop of the user. In the same branch, you can find other keys that contain the paths to the corresponding folders of the user.

Registry information is valid for all versions from Win2000 to Win10 inclusive.


Useful links:
https://social.technet.microsoft.com/wiki/contents/articles/6083.windows-xp-folders-and-locations-vs-windows-7-and-vista.aspx
http://libertyboy.free.fr/computing/reference/envariables/

  • I watched the folders on Windows XP and there was only one folder called Desktop - aaa
  • @ELe remove desktop.ini from it and see its real name. You do not think that for different localization in MS would you make separate folder structures? - rdorn
  • @ELe in general, through desktop.ini any folder can be given an arbitrary name that does not match the original. And the folder will have two names, visible and present - rdorn
  • And in the path to the folder will also be an arbitrary name? I had a desktop on my way. Through the console could not find Desktop. User Variable Contained Desktop - aaa
  • @ELe in the registry path, will be the real name. In general, you can specify any of these names: the present, and a synonym. They are equivalent in this case - rdorn

Modern versions of windows write alias to the Desktop folder "Desktop". Therefore, it would be correct, as I consider to write C: \ Users \% USERPROFILE% \ Desktop.

  • When specifying the path you need to specify the drive C: \? That is, C: \% USERPROFILE% \ Desktop? Or you need to specify the path to the folder with users? - aaa
  • Yes, of course. C: \% USERPROFILE% \ Desktop - Enlightener
  • Without a user folder? (Users) - aaa
  • one
    No with user folder C: \ Users \% USERPROFILE% \ Desktop - Enlightener
  • four
    @Enlightener Do not be fooled. The %USERPROFILE% already contains the drive name and Users. That is, C:\Users\%USERPROFILE%\Desktop will be equivalent to C:\Users\C:\Users\<имя пользователя>\Desktop . - Yaant