首页 > 解决方案 > 检查电话目录(电话到 Linux 的连接)

问题描述

我正在编写一个脚本,将我的手机摄像头拍摄的图像复制到我的 Linux 机器上的 Pictures 文件夹中。

import shutil
from os.path import isdir

source_directory = "mtp://SAMSUNG_SAMSUNG_Android_98897a384e484c5433/Phone/DCIM/Camera/"
destination_directory = "/home/lemons/Pictures/"

def main():       
    if isdir(source_directory):    # If the phone is plugged in correctly
        print("Phone is plugged in correctly.")
    else:
        print("Error: {0} not found! Please make sure the phone is plugged in.".format(source_directory))
    
    if isdir(destination_directory):    # Check if the target directory exists
        print("Target directory is present.")
    else:
        print("Error: {0} not found!".format(destination_directory))
        

if __name__ == "__main__":
    main()

问题是当我在文件资源管理器中查找源目录时,我正在处理不同的目录命名格式:mpt://[insert phone device name]/Phone/DCIM/Cmaera/". 当我运行脚本时,如果说找不到源目录。如何isdir()在手机解锁时运行脚本时检查此目录是否存在?

标签: pythonlinuxdirectorycopy

解决方案


推荐阅读