Skip to content

Instantly share code, notes, and snippets.

@hn5092
Created March 31, 2016 02:13
Show Gist options
  • Save hn5092/cefd488f65e4e1709d38c8095f3723f6 to your computer and use it in GitHub Desktop.
Save hn5092/cefd488f65e4e1709d38c8095f3723f6 to your computer and use it in GitHub Desktop.
mv files to table dir
def moveFile(day: String, fileSystem: FileSystem): Unit = {
val status: Array[FileStatus] = fileSystem.listStatus(new Path(TableConstents.TEMP_TRANSFER_TABLE_PATH + day))
status.foreach {
s =>
if (s.isDirectory) {
fileSystem.listStatus(s.getPath).foreach {
p =>
val path: String = p.getPath.toString
//1.replace path
val newPath = path.replace("/temp/" + day, "")
val tableName: String = "t_stl_exp_transfer_bak"
val checkDay: String = newPath.substring(newPath.indexOf(tableName) + tableName.length + 1, newPath.lastIndexOf("/"))
val newPathDir: String = newPath.substring(0, newPath.lastIndexOf("/"))
if (!fileSystem.exists(new Path(newPathDir))) {
fileSystem.mkdirs(new Path(newPathDir))
}
println(newPath)
fileSystem.rename(p.getPath, new Path(newPath))
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment