有没有办法知道在Windows资源管理器中选择了哪个文件?我一直在看这里发布的教程白痴指南...... 但是描述的行动是:

悬停

上下文

菜单属性

拖放

我想知道是否有一个方法在选择文件时被调用。例如,创建文件的缩略图视图。

感谢。

有帮助吗?

解决方案

以下是我在AutoHotkey中的操作方法:

GetWindowsExplorerSelectedFile(_hWnd)
{
    local selectedFiles, file

    ; I can send ^C and parse Clipboard, but this way don't mess with clipboard at all, seems nicer.
    ; Warning: with this, you get only what is displayed in Explorer!
    ; If you kept the default Windows setting of not displaying file extensions (bad idea...),
    ; you will get partial file names...
    ControlGet, selectedFiles, List, Selected Col1, SysListView321, ahk_id %_hWnd%
    Loop, Parse, selectedFiles, `n  ; Rows are delimited by linefeeds (`n).
    {
        If (A_Index = 1)
        {
            file := A_LoopField
        }
        Else
        {
            ; Indicate that several files are selected, we return only the first one
            ; but count the total number of selected files, to indicate we return a partial result
            ErrorLevel := A_Index
        }
    }
    Return file
}

我从资源管理器的编辑字段中获取路径(容易出现问题!可以不存在或者可以设置为不显示完整路径)。

核心思想是询问Explorer的SysListView32控件所选项目是什么,并获取它们。

现在,这是一个黑客,可能有更简洁的方式......

PS。:还发现:

其他提示

我遇到了这个python脚本。

from win32com.client.gencache import EnsureDispatch 

for w in EnsureDispatch("Shell.Application").Windows(): 
    print w.LocationName + "=" + w.LocationURL 

但我只获得了打开的文件夹而不是该文件夹中当前选定的项目。

任何人都有更多信息?

scroll top