Created getNextFreeFile method in ReplayFileIO to provide the next free file with a filename like FILENAME_X.EXTENSION
This commit is contained in:
@@ -14,6 +14,7 @@ import net.minecraft.network.EnumPacketDirection;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.*;
|
||||
@@ -46,6 +47,21 @@ public class ReplayFileIO {
|
||||
return folder;
|
||||
}
|
||||
|
||||
public static File getNextFreeFile(File file) {
|
||||
if(!file.exists()) return file;
|
||||
File folder = file.getParentFile();
|
||||
String filename = FilenameUtils.getBaseName(file.getAbsolutePath());
|
||||
String extension = FilenameUtils.getExtension(file.getAbsolutePath());
|
||||
|
||||
int i = 1;
|
||||
while(file.exists()) {
|
||||
file = new File(folder, filename+"_"+i+"."+extension);
|
||||
i++;
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
public static List<File> getAllReplayFiles() {
|
||||
List<File> files = new ArrayList<File>();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user