使用 AHK 删除连接的 android 设备上的文件

Delete files on connected android device with AHK

我有一个自动热键脚本,我需要使用自动化删除其中的特定文件。它通过 USB 连接,我可以通过 This PC\myS21\Phone\...\data.txt 在文件浏览器 (windows) 中访问它。我怎样才能用ahk删除这个文件?

我尝试简单地调用 FileDelete, path,但是(据我所知)这不起作用,因为该文件不在计算机文件系统中。

除了基于UI的解决方案,最好的API方法当然是使用adb。而且adb不需要root,只需要在开发者选项中开启adb调试即可。

到运行AHK中的adb文件删除命令:

Run, adb shell rm /sdcard/Download/data.txt

另一种方法是使用Windows系统提供的COM接口:

phone := GetDeviceFolder("Phone Name")
phone.ParseName("Internal Storage\Download\data.txt").InvokeVerb("delete")

GetDeviceFolder(deviceName) {
    shell := ComObjCreate("Shell.Application")
    computer := shell.Namespace("::{20d04fe0-3aea-1069-a2d8-08002b30309d}")
    for item in computer.Items
        if item.Name = deviceName
            return item.GetFolder()
}

来源:https://www.autohotkey.com/boards/viewtopic.php?t=6395#p42773