删除文件-通配符
来源:互联网 发布:洪城网络 编辑:程序博客网 时间:2024/06/05 20:27
公司用到这个了,把原有的Del文件修改了一下
public Boolean DeleteFile() { String sourceFileName = ""; if (sSMBSourceFile == null) { sourceFileName = new File(sSourceFile).getName(); if (sourceFileName.indexOf("*") >= 0) { return DeleteSign(sSourceFile); } else { File fFile = new File(sSourceFile); if (fFile.isFile()) { /* * Set the file , can be deleted */ if (!fFile.canWrite()) { fFile.setWritable(true); } return fFile.delete(); } else if (fFile.isDirectory()) { return pDeleteDirectory(sSourceFile); } else { return true; } } } else { sourceFileName = sSMBSourceFile.getName(); if (sourceFileName.indexOf("*") >= 0) { return DeleteSign(sSourceFile); } else { if (sourceExist) { return deleteSMBFile(sSMBSourceFile); } else { return true; } } } } private Boolean DeleteSign(String sSrcPath) { String sTmpFile = ""; if (sSrcPath.indexOf("smb://") != -1) { SmbFile fTmpFile = defineSmbFile(sSrcPath); if (fTmpFile == null) { return false; } sTmpFile = fTmpFile.getName(); } else { File fTmpFile = new File(sSrcPath); sTmpFile = fTmpFile.getName(); } if (sTmpFile.length() <= 1) { AddLog(EnumLogType.LOGTYPE_ERROR, EnumBuildStatus.BSTATUS_ONGOING, "Incorrect filename: " + sSrcPath); return false; } String sTPF = "*"; String sTPF2 = "*"; if (sTmpFile.indexOf("*.*") == -1) { if (sTmpFile.substring(0, 2).equals("*.")) { sTPF2 = sTmpFile.substring(2).toUpperCase(); } else if (sTmpFile.substring(sTmpFile.length() - 2).equals(".*")) { sTPF = sTmpFile.substring(0, sTmpFile.length() - 2).toUpperCase(); } else { AddLog(EnumLogType.LOGTYPE_ERROR, EnumBuildStatus.BSTATUS_ONGOING, "Invalid filename, please use *.X or X.*: " + sSrcPath); return false; } } Boolean bTotalRlt = true; if (sSrcPath.indexOf("smb://") != -1) { SmbFile file; try { file = defineSmbFile(new SmbFile(sSrcPath).getParent()); if (file != null) { SmbFile[] fileList = file.listFiles(); if (fileList != null) { for (int i = 0; i < fileList.length; i++) { if (fileList[i].isFile()) { String sTmpSrc = fileList[i].getPath(); String fileName = fileList[i].getName(); String fileFirstName = fileName; String fileLastName = ""; if (fileName.lastIndexOf(".") != -1) { fileFirstName = fileName.substring(0, fileName.lastIndexOf(".")); if (fileName.length() > fileName.lastIndexOf(".") + 1) { fileLastName = fileName.substring(fileName.lastIndexOf(".") + 1); } } if (sTPF.equals("*") && !sTPF2.equals("*")) { if (!sTPF2.equals(fileLastName.toUpperCase())) { continue; } } if (!sTPF.equals("*") && sTPF2.equals("*")) { if (!sTPF.equals(fileFirstName.toUpperCase())) { continue; } } if (!deleteSMBFile(fileList[i])) { AddLog(EnumLogType.LOGTYPE_ERROR, EnumBuildStatus.BSTATUS_ONGOING, "Del failed from [" + sTmpSrc + "] "); bTotalRlt = false; break; } else { bTotalRlt = true; } } } } } else { return false; } } catch (Exception ex) { Logger.getLogger(CCommFileOpt.class.getName()).log(Level.SEVERE, null, ex); } } else { File file = new File(sSrcPath.substring(0, sSrcPath.lastIndexOf("/"))); File[] fileList = file.listFiles(); if (fileList != null) { for (int i = 0; i < fileList.length; i++) { if (fileList[i].isFile()) { String sTmpSrc = fileList[i].getAbsolutePath().replace("\\", "/"); String fileName = fileList[i].getName(); String fileFirstName = fileName; String fileLastName = ""; if (fileName.lastIndexOf(".") != -1) { fileFirstName = fileName.substring(0, fileName.lastIndexOf(".")); if (fileName.length() > fileName.lastIndexOf(".") + 1) { fileLastName = fileName.substring(fileName.lastIndexOf(".") + 1); } } if (sTPF.equals("*") && !sTPF2.equals("*")) { if (!sTPF2.equals(fileLastName.toUpperCase())) { continue; } } if (!sTPF.equals("*") && sTPF2.equals("*")) { if (!sTPF.equals(fileFirstName.toUpperCase())) { continue; } } if (!fileList[i].canWrite()) { fileList[i].setWritable(true); } bTotalRlt = bTotalRlt && fileList[i].delete(); if (!bTotalRlt) { AddLog(EnumLogType.LOGTYPE_ERROR, EnumBuildStatus.BSTATUS_ONGOING, "Del failed from [" + sTmpSrc + "] "); bTotalRlt = false; break; } else { bTotalRlt = true; } } } } } return bTotalRlt; }
- 通配符删除文件-Java
- 删除文件-通配符
- Python 通配符删除文件
- Delphi 支持通配符删除文件!
- 删除通配符表示的文件及文件夹
- Linux下通配符批量删除相同文件
- vc 支持通配符的文件删除
- linux下用通配符删除当前目录下包括子目录的相同文件
- 由于工作需要,写了一个关于支持通配符的批量删除文件或文件夹
- 由于工作需要,写了一个关于支持通配符的批量删除文件或文件夹
- Redis 通配符批量删除key
- 文件通配符函数
- linux文件通配符
- hadoop 文件通配符
- Linux之文件通配符
- Linux文件管理--通配符
- linux文件通配符
- Java 通配符匹配查找文件
- 依样画葫芦实现JasperReport客户端本地打印
- A服务器数据库数据插入B服务器数据库(C#控制台应用程序)
- 2013技术发展之我见
- UFLDL练习(PCA and Whitening && Softmax Regression)
- c#如何合并多个word文档中的内容到一个word中
- 删除文件-通配符
- ICS服务无法启动
- 移动互联网的特点
- zoj - 1137 - Girls and Boys(二分图最大独立点集)
- java学习笔记之 --------枚举(enum)
- 基于rs232串口通讯的Verilog设计
- 怎样实现JasperReport循环打印 or 多表打印
- 鼠点点 模拟鼠标运行的小工具
- url传值中文乱码解决方案