From 0d16181e10a4a517a3b6d01f345dd558af39521f Mon Sep 17 00:00:00 2001 From: leebeomjun Date: Thu, 21 Sep 2023 14:08:27 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B9=88=20=EB=94=94=EB=A0=89=ED=86=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=A0=95=EB=A6=AC=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cokr/xit/fims/cmmn/CmmnUtil.java | 34 +++++++++++++++++++ .../java/cokr/xit/fims/cmmn/ftp/FTPUtil.java | 8 ++--- .../xit/fims/crdn/web/Crdn05Controller.java | 6 ++-- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java index b162d84c..e6044b27 100644 --- a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java @@ -1,6 +1,14 @@ package cokr.xit.fims.cmmn; +import java.io.File; + public class CmmnUtil { + + /** + * HTML엔티티코드 문자열을 특수문자로 치환한다. + * @param HTML엔티티코드 문자열 + * @return 치환된 특수문자 + */ public static String escapeHTMLEntity(String str) { str = str.replaceAll("<", "<"); str = str.replaceAll(">", ">"); @@ -9,4 +17,30 @@ public class CmmnUtil { str = str.replaceAll("#39;", "'"); return str; } + + /** + * 하위 폴더가 비워져 있으면 삭제한다. + * @param file 대상 폴더, removeSelf 대상 폴더까지 삭제할 지 여부 + * @return 삭제된 폴더수 + */ + public static int deleteEmptyDir(File file, boolean removeSelf) { + if (!file.isDirectory()) return 0; + + int delCnt=0; + + for (File subFile : file.listFiles()) { + if (subFile.isDirectory()) { + delCnt+=deleteEmptyDir(subFile, true); + } + } + + if(removeSelf) { + if (file.listFiles().length==0) { + file.delete(); + delCnt++; + } + } + + return delCnt; + } } diff --git a/src/main/java/cokr/xit/fims/cmmn/ftp/FTPUtil.java b/src/main/java/cokr/xit/fims/cmmn/ftp/FTPUtil.java index f7757125..f2f5c1b4 100644 --- a/src/main/java/cokr/xit/fims/cmmn/ftp/FTPUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/ftp/FTPUtil.java @@ -117,12 +117,11 @@ public class FTPUtil { // FTP의 파일 리스트와 디렉토리 정보를 취득하는 함수. public static boolean getFileList(FTPClient client, String fileSeparator, String work, List files, List directories) { - System.out.println("work is "+work); // FTP의 디렉토리 커서를 이동한다. try { if (client.changeWorkingDirectory(work)) { - System.out.println("커서이동 성공"); + // 해당 디렉토리의 파일 리스트를 취득한다. for (FTPFile file : client.listFiles()) { @@ -146,12 +145,9 @@ public class FTPUtil { // FTP의 디렉토리 커서를 이동한다. return client.changeWorkingDirectory(fileSeparator); - } else { - System.out.println("커서이동 실패"); } } catch (IOException e) { - System.out.println("유틸 에러"); - e.printStackTrace(); + throw new RuntimeException(); } // 커서 이동에 실패하면 false를 리턴한다. diff --git a/src/main/java/cokr/xit/fims/crdn/web/Crdn05Controller.java b/src/main/java/cokr/xit/fims/crdn/web/Crdn05Controller.java index 808078ae..bfad523e 100644 --- a/src/main/java/cokr/xit/fims/crdn/web/Crdn05Controller.java +++ b/src/main/java/cokr/xit/fims/crdn/web/Crdn05Controller.java @@ -22,6 +22,7 @@ import cokr.xit.base.code.CommonCode; import cokr.xit.base.file.FileInfo; import cokr.xit.base.file.web.FileInfoFactory; import cokr.xit.base.web.ApplicationController; +import cokr.xit.fims.cmmn.CmmnUtil; import cokr.xit.fims.crdn.Crdn; import cokr.xit.fims.crdn.CrdnQuery; import cokr.xit.fims.crdn.dao.CrdnInstMapper; @@ -194,11 +195,10 @@ public class Crdn05Controller extends ApplicationController { String entType = hReq.getParameter("entType"); String fileName = hReq.getParameter("fileName"); - - if(entType.equals("이노")) { try { + Stream walk = Files.walk(Paths.get("files"+File.separator+"tempForIno")); List deleteFilePaths = new ArrayList(); @@ -212,6 +212,8 @@ public class Crdn05Controller extends ApplicationController { saved = (new File(deleteFilePath)).delete(); } + //빈 디렉토리 삭제 + CmmnUtil.deleteEmptyDir(new File("files"+File.separator+"tempForIno"), false); } catch (Exception e) { throw new RuntimeException(); }