Last active
August 29, 2015 14:15
-
-
Save mutterer/26d3a554e130171e47de to your computer and use it in GitHub Desktop.
microscope PC data cleanup script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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