Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion java/src/main/java/ca/uwaterloo/cs489/exercise2/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.*;

public class Job {
private File file;
Expand All @@ -31,5 +32,28 @@ public int processJob() {
return rtn;
}

public int getInput() { return this.input; }
public int getInput() {
return this.input;
}

public void deleteFile(Job job) {
if (job.delete()) {
System.out.println("File deleted successfully");
}
else {
System.out.println("Failed to delete the file");
}
}

public void deleteDirectoryRecursion(Path path) throws IOException {
if (Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)) {
try (DirectoryStream<Path> entries = Files.newDirectoryStream(path)) {
for (Path entry : entries) {
deleteDirectoryRecursion(entry);
}
}
}
Files.delete(path);
System.out.println("Directory deleted");
}
}
4 changes: 4 additions & 0 deletions java/src/main/java/ca/uwaterloo/cs489/exercise2/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ public static void main(String[] args) {
for (Path entry : ds) {
Job job = new Job(entry.toFile());
logger.info(String.format("Job %d yields %d\n", job.getInput(), job.processJob()));
job.deleteFile();
}

deleteDirectoryRecursion(dir);

} catch (IOException e) {
e.printStackTrace();
}
Expand Down