Source code
撰写于 2018-04-13
修改于 2025-01-18
标签
code
views
js code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 export default (t, h, m, s, ms) => { if (!isNaN (h)) t.setHours (h) if (!isNaN (m)) t.setMinutes (m) if (!isNaN (s)) t.setSeconds (s) if (!isNaN (ms)) t.setMilliseconds (ms) return t }
java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 public static void deleteEmptyDir (Path path) throws Exception { HDFSUtils.initFileSystem(); FileStatus[] listFile = HDFSUtils.fs.listStatus(path); if (listFile.length == 0 ) { HDFSUtils.fs.delete(path, true ); return ; } RemoteIterator<LocatedFileStatus> listLocatedStatus = HDFSUtils.fs.listLocatedStatus(path); while (listLocatedStatus.hasNext()) { LocatedFileStatus next = listLocatedStatus.next(); Path currentPath = next.getPath(); Path parentPath=next.getPath().getParent(); if (next.isDirectory()) { if (HDFSUtils.fs.listStatus(currentPath).length == 0 ) { HDFSUtils.fs.delete(currentPath, true ); if (HDFSUtils.fs.listStatus(parentPath).length==0 ){ HDFSUtils.fs.delete(parentPath, true ); } } else { if (HDFSUtils.fs.exists(currentPath)) { AchieveClass.deleteEmptyDir(currentPath); } } } else { long fileLength = next.getLen(); if (fileLength == 0 ) { HDFSUtils.fs.delete(currentPath, true ); } } int length = HDFSUtils.fs.listStatus(parentPath).length; if (length == 0 ){ HDFSUtils.fs.delete(parentPath, true ); } } HDFSUtils.closeFileSystem(); }