zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    P1032 字串变换
    P3203 [HNOI2010]弹飞绵羊
    P3690 【模板】Link Cut Tree (动态树)
    P2147 [SDOI2008]洞穴勘测
    P3950 部落冲突
    Codeforces Round #469 Div. 2题解
    线段树
    SDOI2018退役记
    4.1模拟题
    无旋Treap
  • 原文地址:https://www.cnblogs.com/pythonClub/p/10540675.html
Copyright © 2011-2022 走看看