Last active
January 31, 2021 21:57
-
-
Save Miqueas/e300178d36fb2e80050cc060387826e5 to your computer and use it in GitHub Desktop.
[Lua + GLib] User directories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local lgi = require("lgi") | |
local GLib = lgi.require("GLib", "2.0") | |
--[[ Explanation | |
Some multimedia apps (music players, for example) that uses GLib and related libraries (Gtk, | |
GObject, GStreamer, etc...) commonly auto-detects user directories that contains specific | |
things like music, videos, pictures and documents. That's nice, but... How is it done? | |
Well... Here's the answer: | |
]] | |
-- GLib has the function 'get_user_special_dir()' and takes an argument of type GLib.UserDirectory: | |
local DesktopDir = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_DESKTOP) | |
local DownloadsDir = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_DOWNLOAD) | |
local DocumentsDir = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_DOCUMENTS) | |
local MusicDir = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_MUSIC) | |
local PicturesDir = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES) | |
local PublicShareDir = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PUBLIC_SHARE) | |
local TemplatesDir = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_TEMPLATES) | |
local VideosDir = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_VIDEOS) | |
-- And that's it! Check out the result: | |
print(DesktopDir) | |
print(DownloadsDir) | |
print(DocumentsDir) | |
print(MusicDir) | |
print(PicturesDir) | |
print(PublicShareDir) | |
print(TemplatesDir) | |
print(VideosDir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment