python 判断 hdfs 文件 目录 是否存在

很简单

    filexistchk = "hadoop dfs -test -e " + hdfs_path + ";echo $?"
    filexistchk_output = subprocess.Popen(filexistchk, shell=True, stdout=subprocess.PIPE).communicate()
    if '1' not in str(filexistchk_output[0]):
        return 1
    else:
        return 0

ref:

https://stackoverflow.com/questions/53111903/given-a-hdfs-path-how-do-i-know-if-it-is-a-folder-or-a-file-with-python

你可能感兴趣的:(pyspark,python)