Copy files from phone Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mortygg
Posts: 3
Joined: 14 Nov 2022, 02:14

Copy files from phone

Post by mortygg » 15 Nov 2022, 01:20

Hi everyone,

Im trying to make an AHK script, that copies files from a specific folder on my phone (connected via USB), but i cant get it working.

Udklip.PNG
Udklip.PNG (43.88 KiB) Viewed 1340 times

I have tried using the following, but it's like the path isn't recognized - "Denne pc" is equal to "This pc")

Code: Select all

FileMoveDir, Denne pc\Galaxy A41\Internt lager\DCIM\Camera, C:\test, R

I have also tried using CLSID to open the folder on my phone, but it's not working either:

Code: Select all

Run, ::{20d04fe0-3aea-1069-a2d8-08002b30309d}\Galaxy A41\Internt lager\DCIM\Camera

Does anyone know how to do this? :)

Thanks in advance.
Morty

User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Copy files from phone

Post by mikeyww » 15 Nov 2022, 07:21

Welcome to this AutoHotkey forum!

Others here may know more, but this information might help. Windows uses something called Media Transfer Protocol for media devices such as phones and cameras. This requires special handling. You sometimes have an option to use such devices as regular disk storage, or to assign a drive letter. That would be the way to do it (and it may disable some other media features that you might not need). There are also programs, such as MTPdrive, that can assign a drive letter for you.

There may be some way to use AHK directly to replicate what MTPdrive and similar programs are doing, though I never tried it. If you need that, you may want to do some reading and searching about Media Transfer Protocol.

william_ahk
Posts: 481
Joined: 03 Dec 2018, 20:02

Re: Copy files from phone

Post by william_ahk » 16 Nov 2022, 01:18

Code: Select all

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

DeviceFileCopy("Phone Name\Internal Storage\Folder", "Volume Name (X:)\Folder")

User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Copy files from phone

Post by mikeyww » 16 Nov 2022, 07:07

That's for my library! Thanks, william_ahk.

User avatar
MrDodel
Posts: 96
Joined: 28 Apr 2021, 09:03
Location: Event Horizon

Re: Copy files from phone

Post by MrDodel » 16 Nov 2022, 07:18

@mortygg,
Is this a works laptop at all, I get the impression it could be so maybe Group Policy prevents access to external devices for security reasons.

Just a thought.

Regards
Dodel.
So much universe, and so little time. GNU Sir Terry.

garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: Copy files from phone

Post by garry » 16 Nov 2022, 08:29

I get an iPhone , have only access to photo-folder > Apple iPhone\Internal Storage\DCIM
is it possible to move MP3 and MP4 from computer to iPhone ( and back ) ?

User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Copy files from phone

Post by mikeyww » 16 Nov 2022, 09:26

I did not try william_ahk script, but I found in the past that this requires setting the storage device to storage mode (not media mode), or using one of the techniques to assign a drive letter (which I think is also using storage mode).

mortygg
Posts: 3
Joined: 14 Nov 2022, 02:14

Re: Copy files from phone

Post by mortygg » 17 Nov 2022, 01:22

william_ahk wrote:
16 Nov 2022, 01:18

Code: Select all

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

DeviceFileCopy("Phone Name\Internal Storage\Folder", "Volume Name (X:)\Folder")
Thank alot, it works like a charm!
How would i go about "cut" the files from the last folder, instead of the folder itself? :)

william_ahk
Posts: 481
Joined: 03 Dec 2018, 20:02

Re: Copy files from phone  Topic is solved

Post by william_ahk » 18 Nov 2022, 10:26

@mikeyww :thumbup:
@garry Yes I think so.
Now supporting wildcard and cut! :trollface:

Code: Select all

GetDeviceFolderItem(filepath) {
    shell := ComObjCreate("Shell.Application")
    computer := shell.Namespace("::{20d04fe0-3aea-1069-a2d8-08002b30309d}")
	filepath := StrSplit(filepath, "\", , 2)
	deviceName := filepath[1], folderName := filepath[2]
    for item in computer.Items
        if item.Name = deviceName
            return filepath[2] == "" ? item : item.GetFolder().ParseName(filepath[2])
}
DeviceFileCopy(src, dest) {
	SplitPath, src, filename, dir
	if (InStr(filename, "*")) {
		regexMask := StrReplace(StrReplace(StrReplace(filename, ".", "[.]"), "*", ".*"), "?", ".")
		src := dir
	}
	oSrc := GetDeviceFolderItem(src)
	oDest := GetDeviceFolderItem(dest)
	if (src = dir) {
		for item in oSrc.GetFolder().Items {
			if RegExMatch(item.Name, regexMask) {
				item.InvokeVerb("copy")
				oDest.InvokeVerb("paste")
			}
		}
	} else {
		oSrc.InvokeVerb("copy")
		oDest.InvokeVerb("paste")
	}
}
DeviceFileMove(src, dest) {
	SplitPath, src, filename, dir
	if (InStr(filename, "*")) {
		regexMask := StrReplace(StrReplace(StrReplace(filename, ".", "[.]"), "*", ".*"), "?", ".")
		src := dir
	}
	oSrc := GetDeviceFolderItem(src)
	oDest := GetDeviceFolderItem(dest)
	if (src = dir) {
		for item in oSrc.GetFolder().Items {
			if RegExMatch(item.Name, regexMask) {
				item.InvokeVerb("cut")
				oDest.InvokeVerb("paste")
			}
		}
	} else {
		oSrc.InvokeVerb("cut")
		oDest.InvokeVerb("paste")
	}
}
; Usage
DeviceFileCopy("Phone Name\Internal Storage\Folder\File*", "Volume Name (X:)\Folder")
; Example
DeviceFileCopy("motorola edge s\Internal Storage\Download\*.mp4", "Resources (G:)\Memes I saved on my 256gb phone")

mortygg
Posts: 3
Joined: 14 Nov 2022, 02:14

Re: Copy files from phone

Post by mortygg » 09 Dec 2022, 01:17

Sorry for the late reply.

@william_ahk it works like a charm! Thanks you so much - it's really appreciated :)

User avatar
redsonja
Posts: 10
Joined: 24 Nov 2020, 06:13

Re: Copy files from phone

Post by redsonja » 30 Jan 2023, 14:46

I hope it's okay to ask a question in a solved thread. Especially with such a noob question.
So I tried the first and simplest version of william_ahk first. To be totally open, I didn't understand at all how it works. But hey, let's give it a shot.
william_ahk wrote:
16 Nov 2022, 01:18

Code: Select all

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

DeviceFileCopy("Phone Name\Internal Storage\Folder", "Volume Name (X:)\Folder")
I inserted my paths to my best knowledge, but nothing happens. The device (Huawei Mate 20 X) is mounted and accessible, the destination (S:) likewise. What could be my mistake? I have a feeling, I didn't insert some path. Thanks in advance!

Code: Select all

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

DeviceFileCopy("HUAWEI Mate 20 X\Interner Speicher\MEDIEN\Diary", "USB-Laufwerk (S:)\Folder")

william_ahk
Posts: 481
Joined: 03 Dec 2018, 20:02

Re: Copy files from phone

Post by william_ahk » 30 Jan 2023, 23:09

redsonja wrote:
30 Jan 2023, 14:46

Code: Select all

DeviceFileCopy("HUAWEI Mate 20 X\Interner Speicher\MEDIEN\Diary", "USB-Laufwerk (S:)\Folder")
Path looks valid. Does the destination folder exist? I forgor to handle folder creation.

User avatar
redsonja
Posts: 10
Joined: 24 Nov 2020, 06:13

Re: Copy files from phone

Post by redsonja » 13 Feb 2023, 04:56

william_ahk wrote:
redsonja wrote:
30 Jan 2023, 14:46

Code: Select all

DeviceFileCopy("HUAWEI Mate 20 X\Interner Speicher\MEDIEN\Diary", "USB-Laufwerk (S:)\Folder")
Path looks valid. Does the destination folder exist? I forgor to handle folder creation.
Sorry for the delay, I was abroad and forgot to sync my login credentials. Yes, I tried with existing folders but still nothing...

Post Reply

Return to “Ask for Help (v1)”