How can I list all .desktop files in usr/share/applications using 'ls /usr/share/applications' command and make it a list variable in python3.7?
like
list1 = replayof('command')
print1 = list(list1)
print(print1)
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Sign up to join this communityIt's not trivial to understand your question, and it's probably the wrong stackexchange for this, because it's more python than Ubuntu.
That being said, I believe the code you are looking for is
import os
print(os.listdir('/usr/share/applications'))
Unless your question is really about how to list all files that end in .desktop
? Then it would be
ls /usr/share/applications/*.desktop
.
For more on this, you may want to look into wildcards
and globbing
.
I'll leave the list part as an exercise to the reader.