Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
10
rated 0 times [  10] [ 0]  / answers: 1 / hits: 3749  / 3 Years ago, thu, may 27, 2021, 6:54:41

I am making a script and I am looking for a way to get the variable names for Desktop, Music, Documents, Pictures and others Folders. Depending on the language they change. For example Desktop in Spanish is Escritorio. So how can I get the folder directory without needing to find out what language the user is using or having to make several IF statements for each language.


More From » bash

 Answers
4

There is a tool called xdg-user-dir that retrieves user directories paths



documents_path=$(xdg-user-dir DOCUMENTS)
echo $documents_path


From the docs:




xdg-user-dir looks up the current path for one of the special XDG user dirs.



This command expects the name of an XDG user dir as argument. The possible names are:




  • DESKTOP

  • DOWNLOAD

  • TEMPLATES

  • PUBLICSHARE

  • DOCUMENTS

  • MUSIC

  • PICTURES

  • VIDEOS




I'm using Ubuntu 16.04, I don't really know if this is available in previous releases.


[#35262] Thursday, May 27, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
soahan

Total Points: 230
Total Questions: 123
Total Answers: 123

Location: Maldives
Member since Tue, Dec 21, 2021
2 Years ago
;