如何判断hdfs(hadoop)上的路径是文件还是目录。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何判断hdfs(hadoop)上的路径是文件还是目录。相关的知识,希望对你有一定的参考价值。

比如我的hadoop下有个目录“/user/lee/”,该目录下有个文件test,如果用String s = "/user/lee/test"表示文件路径,则判断其是文件还是目录的代码怎么写啊?问题解决后再给50分,先谢谢了。

参考技术A 先用hdfsGetPathInfo 得到一个hdfsFileInfo类型的结构体,
get_real_path(dsh, s, real_path);
hdfsFileInfo * pt_hdfs_file_info = hdfsGetPathInfo(hdfs,real_path);//
这个结构体中有个kind属性,就是来区分是文件还是目录
typedef struct
tObjectKind mKind; /* file or directory */
char *mName; /* the name of the file */
tTime mLastMod; /* the last modification time for the file in seconds */
tOffset mSize; /* the size of the file in bytes */
short mReplication; /* the count of replicas */
tOffset mBlockSize; /* the block size for the file */
char *mOwner; /* the owner of the file */
char *mGroup; /* the group associated with the file */
short mPermissions; /* the permissions associated with the file */
tTime mLastAccess; /* the last access time for the file in seconds */
hdfsFileInfo;
参考技术B 用ls命令, 如果返回一行说明是文件,如果多行则表示目录
hadoop fs -ls $path | grep $path | wc -l追问

API有直接操作Hadoop的索引(FsImage)的吗?我的意思是直接用API实现,我知道脚本命令。如果你可以解决这个问题也可以
http://zhidao.baidu.com/question/432606039.html?quesup2&oldq=1

参考技术C hadoop fs -ls $path | grep $path | wc -l 参考技术D 这个简单 创建一个FileStatus 对象 调用isDir()方法 返回一个布尔值 我想这个你该懂的吧。。这个你多看看api就知道。。不知道你能满意不追问

这个我懂并且已经解决了 能解决下面这个问题吗?
API有直接操作Hadoop的索引(FsImage)的吗?我的意思是直接用API实现,我知道脚本命令。如果你可以解决这个问题也可以
http://zhidao.baidu.com/question/432606039.html?quesup2&oldq=1

以上是关于如何判断hdfs(hadoop)上的路径是文件还是目录。的主要内容,如果未能解决你的问题,请参考以下文章

hadoop怎么访问hdfs路径

如何把hdfs上的多个目录下的文件合并为一个文件

hadoop内部表直接添加文件

如何把hdfs上的多个目录下的文件合并为一个文件

Hadoop MapReduce 文件路径过滤 GlobStatus 与 PathFilter

Hadoop MapReduce 文件路径过滤 GlobStatus 与 PathFilter