I am writing an automation test using python, where an android app records an audio and stores it in a specific directory within the internal storage (sdcard0) of the android device.

I need to check whether the recording (recordingX.mp3) actually exists with the same name within the specific directory or not.. If YES, the latest file should be given a new name.

As part of this, I tried writing code.. But I was not able to locate the exact path for the recorded audio..
This is the tree structure of the actual location..

        -> Internal Storage
            -> Maverick

  >>> import os
    >>> print os.path.exists('sdcard/Maverick')
    >>> print os.path.exists('sdcard/Maverick/recording0.mp3')
    >>> print os.path.exists('sdcard0/Maverick')
    >>> print os.path.exists('sdcard0/Maverick/')

Please help me out in writing the code..

Recommended Answers

All 10 Replies

Start with


This is what i get, when I run - "print(os.listdir('/'))"

>>> import os
>>> print(os.listdir('/'))
['tmp', 'root', 'run', 'bin', 'lost+found', 'etc', 'boot', 'proc', 'mnt', 'cdrom', 'sys', 'lib64', 'srv', 'lib', 'home', 'var', 'usr', 'dev', 'media', 'lib32', 'sbin', 'opt', 'vmlinuz', 'initrd.img']

I am using ubuntu14.04.. The result what i get are the directories within ubuntu..
I need to go to directory within my android device..

Sorry I thought the program was running on your android device

Do you have any idea on how to get into android device (internal storage) directory..?? Using python test code.. In ubuntu14.04..
I have connected my device to the notebook, and I have checked USB debugging..

No I don't know how to do that. I tried with a Samsung phone but it does not work. From what I read elsewhere, a solution is to install sshdroid on your android device (this is a ssh server) and connect the device through ssh from any computer.

Thank You.. :) I will try to do that..

With a kde desktop (kubuntu), there may be a solution using module PyKDE4.solid. This module can discover and connect hardware devices connected to the computer See Here.

On my computer, I can run

from PyKDE4.solid import *

for d in Solid.Device.allDevices():                                                                                                              
    print d.udi()

this prints a list of all devices.

It should work because KDE's solid library is used by the dolphin file manager to access the Samsung phone as a camera device and display its files hierarchy.

Nah.. I have to get it done on Ubuntu itself.. :)

I got the solution for, "Checking for recording in specific directory".. You need to mount your phone for that.. Below is the code..

      os.system("killall gvfs-gphoto2-volume-monitor")
            os.system("killall gvfs-mtp-volume-monitor")
            dir = os.path.dirname("mountName/")
            if not os.path.exists(dir):
                os.system("sudo mkdir mountName")
            os.system("sudo chmod 777 mountName")
            os.system("sudo mtpfs -o allow_other /media/mountName")

            #You will get the list of Contents within your physical device..
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.