擅长:python、mysql、java
<p>您可能还希望移动/或复制文件而不包含其子目录</p>
<pre><code>import os
source_dir = "/mnt/yourplateform/source"
dest_dir= "/mnt/yourplateform/destination//"
list_of_files=[]
fs = spark._jvm.org.apache.hadoop.fs.FileSystem.get(spark._jsc.hadoopConfiguration())
path_exists = fs.exists(spark._jvm.org.apache.hadoop.fs.Path(source_dir))
if path_exists == True:
file_list = fs.listFiles(spark._jvm.org.apache.hadoop.fs.Path(source_dir), True)
while file_list.hasNext():
file = file_list.next()
list_of_files.append(str(file.getPath()))
for file in list_of_files:
dbutils.fs.mv(file, os.path.join(dest_dir, os.path.basename(file)), recurse=True)
</code></pre>