public Boolean DeleteFile() {
if (sSMBSourceFile == null) {
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 {
if (sourceExist) {
return deleteSMBFile(sSMBSourceFile);
} else {
return true;
}
}
}
现在是这个方法,怎么改动,然后支持通配符操作。、求大神。。参考下面的代码。
public void deleteSigns(String sSrcPath) {
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 (!sTPF2.equals(fileFirstName.toUpperCase())) {
continue;
}
}
if (这个方法怎么写?) {
AddLog(EnumLogType.LOGTYPE_ERROR, EnumBuildStatus.BSTATUS_ONGOING, "Del failed from [" + sTmpSrc + "] ");
bTotalRlt = false;
break;
} else {
bTotalRlt = true;
}
}
}
}Java通配符
if (sSMBSourceFile == null) {
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 {
if (sourceExist) {
return deleteSMBFile(sSMBSourceFile);
} else {
return true;
}
}
}
现在是这个方法,怎么改动,然后支持通配符操作。、求大神。。参考下面的代码。
public void deleteSigns(String sSrcPath) {
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 (!sTPF2.equals(fileFirstName.toUpperCase())) {
continue;
}
}
if (这个方法怎么写?) {
AddLog(EnumLogType.LOGTYPE_ERROR, EnumBuildStatus.BSTATUS_ONGOING, "Del failed from [" + sTmpSrc + "] ");
bTotalRlt = false;
break;
} else {
bTotalRlt = true;
}
}
}
}Java通配符
假设命令行传来的参数叫wild。用正则
String regex = "^" + wild.replace(".", "\\.").replace("*", ".*").replace("?", ".?") + "$";判断时候
if (file.getName().matches(regex)) {
...
}