Reputation: 1202
I have an autohotkey script, and I need to delete a specific file on it using automation. It's connected via usb, and I can access it in the file explorer (windows) via This PC\myS21\Phone\...\data.txt
. How can I delete this file with ahk?
I tried simply calling FileDelete, path
, but (as I understand), this wont work because the file is not within the computers filesystem.
Upvotes: 0
Views: 252
Reputation: 373
Apart from UI-based solutions, the best API way is to of course use adb. And adb doesn't require root, it just needs to have adb debugging enabled in developer options.
To run the adb file delete command in AHK:
Run, adb shell rm /sdcard/Download/data.txt
Another way is to use the COM Interface provided by the Windows system:
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()
}
Source: https://www.autohotkey.com/boards/viewtopic.php?t=6395#p42773
Upvotes: 1