Warlax56
Warlax56

Reputation: 1202

Copy files from COM device using AHK

I have a function which can effevtively copy a file from my android device,

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()
}

save_data_file()
{
    GuiControlGet,phonename
    GuiControlGet,datapath
    GuiControlGet,savepath
    phone := GetDeviceFolder(phonename)
    phone.ParseName(datapath).InvokeVerb("copy")
}

however, I can't figure out how "paste" it to a local drive. I know it's in the clipboard because I can paste it manually after running this function.

Upvotes: 0

Views: 213

Answers (2)

Warlax56
Warlax56

Reputation: 1202

I did it like using this helper function

InvokeVerb(path, menu, validate=True) {
    ;by A_Samurai
    ;v 1.0.1 http://sites.google.com/site/ahkref/custom-functions/invokeverb
    objShell := ComObjCreate("Shell.Application")
    if InStr(FileExist(path), "D") || InStr(path, "::{") {
        ;~ MsgBox % path
        objFolder := objShell.NameSpace(path)   
        ;~ MsgBox % namespace(path) . "k"
        objFolderItem := objFolder.Self
    }
    else {
        SplitPath, path, name, dir
        ;~ MsgBox % path . "`n" name . "`n" . dir
    ;~ loop, % path0
        ;~ MsgBox % path%A_index%
    objFolder := objShell.NameSpace(dir)
    objFolderItem := objFolder.ParseName(name)


    }
    if validate {
    colVerbs := objFolderItem.Verbs   
    colVerbs.Count
        loop % colVerbs.Count {
            verb := colVerbs.Item(A_Index - 1) 
            retMenu := verb.name
            StringReplace, retMenu, retMenu, &       
            if (retMenu = menu) {
            verb.DoIt
                Return True
            }
        }


        Return False
    } else
        objFolderItem.InvokeVerbEx(Menu)
}   

then I just did this: InvokeVerb(savepath, "Paste", "false")

Upvotes: 0

skygate
skygate

Reputation: 373

The local disk also needs to be handled by COM.

Example:

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()
}

save_data_file(src, dest) {
    src := StrSplit(src, "\", , 2)
    dest := StrSplit(dest, "\", , 2)
    
    GetDeviceFolder(src[1]).ParseName(src[2]).InvokeVerb("copy")
    GetDeviceFolder(dest[1]).ParseName(dest[2]).InvokeVerb("paste")
}

save_data_file("Phone Name\Internal Storage\Download\5a5f641e9893c.jpg", "Disk Name (E:)\incoming")

Upvotes: 1

Related Questions