0

I want to transfer a file from my windows 10 PC to my android phone via USB but I can't seem to get it to work and the only info I can find is for Raspberry Pi.

The code I did try is:

import os
import shutil

#path
path = "'Deze pc'/'HUAWEI Mate 10 lite'/'Interne opslag'"

# List files and directories
# in '/home/User/Documents'
print("Before copying file:")
print(os.listdir(path))

#Source path
source = "C:/Users/Tim/PycharmProjects/project1/testfile.jpg"

# Print file permission
# of the source
perm = os.stat(source).st_mode
print("File Permission mode:", perm, "\n")

# Destination path
destination = "'Deze pc'/'HUAWEI Mate 10 lite'/'Interne opslag'/photos"

# Copy the content of
# source to destination
dest = shutil.copy(source, destination)

# List files and directories
# in "/home / User / Documents"
print("After copying file:")
print(os.listdir(path))

# Print file permission
# of the destination
perm = os.stat(destination).st_mode
print("File Permission mode:", perm)

# Print path of newly
# created file
print("Destination path:", dest)

But this just gives me a 'FileNotFoundError: [Errno 2] No such file or directory' error. The folder is definitely there but maybe I did some bad formatting?

I hope anyone can help me fix this problem!

  • On what line does the error occur? – Rusty Widebottom Jun 06 '20 at 15:42
  • @RustyWidebottom It occured on line 10, thanks for taking the time to help me :D – Tim Nieland Jun 06 '20 at 17:32
  • Does the PC mount the phone as a USB device, with its own drive letter? Can you see the phone's folder(s) in Windows Explorer? If so, you will want to use that path. If your phone is not visible in Windows Explorer, then you'll have to use some more technology. There are some suggestions in [this question](https://stackoverflow.com/questions/11161747/how-to-access-an-mtp-usb-device-with-python). – Rusty Widebottom Jun 06 '20 at 18:11
  • Thank you! Windows Explorer doesn't give a letter to the phone but I can access all of the files. I'll give it another go. Thank you! – Tim Nieland Jun 07 '20 at 11:07

0 Answers0