递归文件读取火花流

2024-04-27 03:11:54 发布

您现在位置:Python中文网/ 问答频道 /正文

流目录是主目录,其中有多个子目录。你知道吗

我想通过spark流来实现这个功能,spark流访问每个子文件夹并从中捕获文件。你知道吗

import os
rootdir = 'C:\user\Data_Sources'

for subdir, dirs, files in os.walk(rootdir):
    for file in files:
        temp = os.path.join(subdir, file)

到目前为止,我已经这样做了,但它只适用于3个子目录。如果我按照子目录增加'*'的数量,那么spark streaming只读取最后两个目录中的文件,而不读取以前的其他目录。你知道吗

 df = spark.readStream.text('file:///home/user/stream1.0/*/*/*', wholetext=True)

Tags: 文件inimport功能目录文件夹foros