Skip to main content

pywinselect

PyPI version Python versions License: MIT

Get selected files and folders in Windows.

Installation

pip install pywinselect

What it does

pywinselect detects which files or folders you have selected in Windows, regardless of where they are.

It works in:

  • File Explorer - Any open Explorer window
  • Desktop - Files and folders selected on your desktop

Returns absolute paths to everything selected. If nothing is selected, returns an empty list.

Why use it

When building automation tools, you often need to know what the user has selected. Without this library, you'd have to:

  • Write 100+ lines of win32 API code
  • Handle File Explorer and Desktop separately
  • Deal with clipboard backup/restore
  • Debug why it doesn't work on Desktop

pywinselect solves this in one line.

Use cases

  • Stream Deck scripts - Create buttons that act on selected files
  • Keyboard macros - Automate repetitive file operations
  • Custom context menus - Build tools that work with selections
  • Productivity apps - Quick actions on currently selected items
  • Batch processing - Process whatever the user has selected

Usage

from pywinselect import get_selected

# Get all selected items (Desktop + Explorer)
files = get_selected()

# Filter by type
only_files = get_selected(filter_type="files")
only_folders = get_selected(filter_type="folders")

# Get selection from specific location
desktop_only = get_selected(only_desktop=True)
explorer_only = get_selected(only_explorer=True)

API

get_selected(filter_type=None, only_desktop=False, only_explorer=False) -> list[str]

Returns list of absolute paths to selected items.

Parameters:

  • filter_type (optional): Filter results by type
    • None - Return both files and folders (default)
    • "files" - Return only files
    • "folders" - Return only folders
  • only_desktop (optional): If True, only get selection from Desktop
  • only_explorer (optional): If True, only get selection from File Explorer

Returns:

  • list[str] - Paths to selected files/folders
  • [] - Empty list if nothing is selected

Raises:

  • ValueError - If both only_desktop and only_explorer are True

Examples:

>>> get_selected()
['C:\\Users\\John\\file.txt', 'C:\\Users\\John\\Documents']

>>> get_selected(filter_type="files")
['C:\\Users\\John\\file.txt']

>>> get_selected(filter_type="folders")
['C:\\Users\\John\\Documents']

>>> get_selected(only_desktop=True)
['C:\\Users\\John\\Desktop\\file.txt']

>>> get_selected(only_explorer=True)
['C:\\Users\\John\\Downloads\\file.txt']

>>> get_selected(only_desktop=True, only_explorer=True)
ValueError: Cannot set both only_desktop and only_explorer to True

How it works

Uses official Windows Shell COM APIs (IShellView, IDataObject) - the same interfaces Windows Explorer uses internally.

Safe by design:

  • Read-only operations
  • No keyboard simulation
  • No clipboard modifications
  • No system state changes

Requirements

  • Python 3.10+
  • Windows
  • pywin32

License

MIT

Release files for pywinselect 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pywinselect 0.2.1
File Size Uploaded
pywinselect-0.2.1.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pywinselect 0.2.1
File Interpreter ABI Platform
pywinselect-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.4 kB

Release files / pywinselect-0.2.1.tar.gz

Download URL pywinselect-0.2.1.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
610ea4a0e692c1f94a5df20d7182858925dfceb0dcb53567b40c88f8c63f359c
BLAKE2b-256 checksum
How to use checksums
96350c3be5360b0845f897715670f5ecffa52e95d2e969c395f66fec5745d6fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release files / pywinselect-0.2.1-py3-none-any.whl

Download URL pywinselect-0.2.1-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2196aeae49c798d75201b557625b306961ff80aeab7c794a92ed0ed6f050bc4e
BLAKE2b-256 checksum
How to use checksums
48f6ec63d25af4f5ee2632d354b1d3c924a59445d591d7c1c349e9c7e1b6cba0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page