Skip to content

Commit

Permalink
Issue #47 - Implements a File filter to find all the files starting w…
Browse files Browse the repository at this point in the history
…ith a name
  • Loading branch information
GrazianoCapelli committed Apr 27, 2021
1 parent 4cbc7d0 commit 40a9964
Showing 1 changed file with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.greenrobot.eventbus.Subscribe;

import java.io.File;
import java.io.FileFilter;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -692,6 +693,22 @@ private void DeleteFile(String filename) {
}


public File[] FindFile(String path, final String nameStart) {
File _path = new File(path);
try {
return _path.listFiles(new FileFilter() {
@Override
public boolean accept(File file) {
String name = file.getName(); //.toLowerCase();
return name.startsWith(nameStart);
}
});
} catch (Exception e) {
return null;
}
}


/* NOT USED, Commented out
private boolean FileExists(String filename) {
File file = new File(filename);
Expand Down Expand Up @@ -1630,15 +1647,18 @@ public void run() {
}
if (track != null) {
// Delete track files
DeleteFile(Environment.getExternalStorageDirectory() + "/GPSLogger/AppData/" + track.getName() + ".txt");
DeleteFile(Environment.getExternalStorageDirectory() + "/GPSLogger/AppData/" + track.getName() + FILETYPE_KML);
DeleteFile(Environment.getExternalStorageDirectory() + "/GPSLogger/AppData/" + track.getName() + FILETYPE_GPX);
for (File f : FindFile(Environment.getExternalStorageDirectory() + "/GPSLogger/AppData", track.getName())) {
Log.w("myApp", "[#] GPSApplication.java - Deleting: " + f.getAbsolutePath());
DeleteFile(f.getAbsolutePath());
}
// Delete thumbnail
DeleteFile(getApplicationContext().getFilesDir() + "/Thumbnails/" + track.getId() + ".png");
// Delete exported files
if (DeleteAlsoExportedFiles) {
// Delete exported files
DeleteFile(Environment.getExternalStorageDirectory() + "/GPSLogger/" + track.getName() + ".txt");
DeleteFile(Environment.getExternalStorageDirectory() + "/GPSLogger/" + track.getName() + FILETYPE_KML);
DeleteFile(Environment.getExternalStorageDirectory() + "/GPSLogger/" + track.getName() + FILETYPE_GPX);
for (File f : FindFile(Environment.getExternalStorageDirectory() + "/GPSLogger", track.getName())) {
Log.w("myApp", "[#] GPSApplication.java - Deleting: " + f.getAbsolutePath());
DeleteFile(f.getAbsolutePath());
}
}

TracksDeleted++;
Expand Down

0 comments on commit 40a9964

Please sign in to comment.