Skip to content

Instantly share code, notes, and snippets.

@mutterer
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mutterer/26d3a554e130171e47de to your computer and use it in GitHub Desktop.
Save mutterer/26d3a554e130171e47de to your computer and use it in GitHub Desktop.
microscope PC data cleanup script
// On windows, permanently delete files:
// * of a certain type
// * older than a certain year
// * that do not have one of a set of keywords
type="lsm";
keepFrom = 2014;
words= newArray("config","setting");
dir = getDirectory("Choose a Directory ");
count = 1;
listFiles(dir);
function listFiles(dir) {
list = getFileList(dir);
for (i=0; i<list.length; i++) {
if (endsWith(list[i], "/"))
listFiles(""+dir+list[i]);
else {
path = dir + list[i];
date = File.dateLastModified(path);
date = split(date);
year = date[date.length-1];
if ((endsWith(path,type))&&(year<keepFrom )&&(!hasWord(path))) {
path = replace(path,"/","\\");
done = exec ("cmd", "/c", "del", path);
print (year,path);
}
}
}
}
function hasWord(s) {
result = false;
for (w=0;w<words.length;w++){
if (indexOf(toLowerCase(s),words[w])>-1) result =true;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment