Created
March 31, 2016 02:13
-
-
Save hn5092/cefd488f65e4e1709d38c8095f3723f6 to your computer and use it in GitHub Desktop.
mv files to table dir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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