简体   繁体   中英

Get file path of the highlighted files using nautilus script

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM