Python Kivy writes / read the file on the SD card

Path to SD card

from jnius import autoclass  # SDcard Android

# Get path to SD card Android
try:
    Environment = autoclass('android.os.Environment')
    sdpath = Environment.get_running_app().getExternalStorageDirectory()

# Not on Android
except:
    sdpath = App.get_running_app().user_data_dir

user_data_dir also works on Android, but it relies on a /sdcard symlink which is becoming outdated. I don't know for IOS or Windows Phone though.

Copy to SD card

import shutil

sdpathfile = os.path.join(sdpath, 'filename')
shutil.copyfile(os.path.join('folder', 'filename2'), sdpathfile)


=====================
FileChooserListView:
    id: filechooser
    path: "/your/path"

=====================

To find a directory on your system with python, you can do something like this:

import os

for root, dirs, files in os.walk("/"):
    for name in dirs:
        if name == "DCIM":
            print(root, name)

Just be aware that it might find two or more directories named DCIM, on your sdcard and internal storage.

转载于:https://www.cnblogs.com/pythonClub/p/10540675.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值