Skip to content

Instantly share code, notes, and snippets.

@mlhaufe
Created January 6, 2012 05:59
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 mlhaufe/1569247 to your computer and use it in GitHub Desktop.
Save mlhaufe/1569247 to your computer and use it in GitHub Desktop.
Lookup known filetype (JScript)
//Reference: <https://groups.google.com/group/comp.lang.javascript/browse_thread/thread/684ad16518c837a2/67d00aa5dbe854c2?show_docid=67d00aa5dbe854c2>
var listFileTypes = (function(){
var fso = new ActiveXObject("Scripting.FileSystemObject");
var shell = new ActiveXObject("WScript.Shell");
function isKnown(file){
var fName = file.Name;
//the rules of capitalization are strange in windows...
//there are rare cases where this can fail
//for example: .HKEY_CLASSES_ROOT\.HeartsSave-ms
var ext = fName.slice(fName.lastIndexOf(".")).toLowerCase();
try{
shell.RegRead("HKCR\\"+ext+"\\");
return "Yes"
} catch(e){
return "No"
}
}
return function(folder){
var files = new Enumerator(fso.GetFolder(folder).Files);
for(;!files.atEnd();files.moveNext()){
var file = files.item();
WScript.Echo(file.Name + "\t" + file.Type + "\t" + isKnown(file));
}
}
})()
listFileTypes("C:\\test")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment