Using java and FTP I managed to create a backup of a file by appending the TimeStamp with the file name, like
File: a.html
Backup: a_Date_Time.html
but now when as I create a backup of the previous Backup, I get
File: a_Date_Time.html
Backup: a_Date_Time_Date_Time.html
What is the best way to do this? And also Im trying to create a hashmap with, Original file as the key and all the backup as List of FtpFileInfo type
public HashMap<FtpFileInfo, List<FtpFileInfo>> viewFileMap(String directory) throws UnsupportedEncodingException {
List<FtpFileInfo> file = gate.list("./" + URLDecoder.decode(directory, "UTF-8") + "/");
fileMap = new HashMap<>();
for (int i=0;i<file.size();i++){
if(!file.get(i).isDirectory()){
String name = file.get(i).getFilename().substring(0,file.get(i).getFilename().lastIndexOf("."));
int length = name.length();
fileList = new ArrayList<>();
if(!name.matches("[\\w,\\s-]+_\\d{8}_\\d{6}")){
for(int j=i+1;j<file.size();j++){
if(!file.get(j).isDirectory() && file.get(j).getFilename().substring(0,file.get(j).getFilename().lastIndexOf(".")).matches("[\\w,\\s-]+_\\d{8}_\\d{6}")){
String vocd = file.get(j).getFilename();
String fileName = vocd.substring(0, vocd.lastIndexOf("_"));
String finalFileName = fileName.substring(0, fileName.lastIndexOf("_"));
String ss = vocd.substring(vocd.substring(0, vocd.lastIndexOf("_")).lastIndexOf("_") + 1);
String timeStamp = ss.substring(0,ss.lastIndexOf("."));
if(name.equals(finalFileName) && isTimeStampValid(timeStamp)){
fileList.add(file.get(j));
}
}
}
fileMap.put(file.get(i),fileList);
}
else {
continue;
}
}else {
fileMap.put(file.get(i),null);
}
}
return fileMap;
}
It works ok for
a_Date_Time.html and a.html
type files, but when I create a Backup of a backup, it doesnt work, is there a way to create such a hashmap?