Search code examples
pythondirectorynautilus

opening a parent folder and highlighting particular child in default file browser using python


I am using following code to open a folder in default file browser.

if os.name == 'mac':
  subprocess.call(('open', folderPath))
elif os.name == 'nt':
  subprocess.call(('start', folderPath))
elif os.name == 'posix':
  subprocess.call(('xdg-open', folderPath))

Now the problem is I want to highlight the child folder/file which was selected earlier. Is there any way to do it? If not for all, at least for nautilus?


Solution

  • xdg-open doesn't support this, so it has to be done on a per-app basis. After poking around the Nautilus code, I don't think it has this feature either. So, yeah, you're pretty much out of luck.

    For Windows Explorer, you can use

    subprocess.call(("explorer", "/select,", file_path))