I want to get file paths of the files that are selected. I have being try this for the entire day now with no luck.
For example by clicking on the script "filename.py", I would like to get that path of the highlighted directory.
Looking at the documentation of Nautilus scripts you can get the paths to selected files using the environment variable NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
. In Python you can get its value using os.environ
and then later you can use os.path
's functions to do operations on the paths:
import os
paths = os.environ['NAUTILUS_SCRIPT_SELECTED_FILE_PATHS'].splitlines()
for p in paths:
if os.path.isdir(p):
print p
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.