Dr J R Stockton
2012-01-03 17:09:48 UTC
In Windows Script Host, given a File Object with properties including
Name and Type, is there a direct guaranteed infallible way in
JScript/VBScript to find whether the file is a known Type?
Examples :
FILENAME TYPE KNOWN
LONGFILENAME.HTML Firefox Document Yes
SEAKFYLE.OK6 OK6 File No
SEAKFYLE.ZIP Compressed (zipped) Folder Yes
SEEK.$$$ $$$ File No
SEEK.BAT MS-DOS Batch File Yes
SEEK.VBS VBScript Script File Yes
For those, it suffices to test, case-dependently, whether the Extension
appears as a word in the Type : if it does not do so, then the file must
be a known Type. But the converse is only reliable if one can be sure
that a known extension cannot ever, in any natural language, occur as a
word in the corresponding Type string.
Consider the possibility of a default browser being called "View Your
HTML", for example - unlikely, but possible. Or that of a file with
extension "File".
The application is SEAKFYLE, via
<http://www.merlyn.demon.co.uk/programs/32-bit/00index.htm>, using
Options X3 and X4. The current code is in a paragraph currently starting
at Line 281 :
if (Eggs == 3 || Eggs == 4) { S = Item.Path
S = S.substring(S.lastIndexOf(".") + 1) // Extn
if (Eggs == 4 ^ new RegExp("\\b"+S+"\\b").test(Item.Type)) return }
Eggs 3 returns for unknown types; Eggs 4 for known ones. In JScript,
the token ^ means "Exclusive-Or".
Name and Type, is there a direct guaranteed infallible way in
JScript/VBScript to find whether the file is a known Type?
Examples :
FILENAME TYPE KNOWN
LONGFILENAME.HTML Firefox Document Yes
SEAKFYLE.OK6 OK6 File No
SEAKFYLE.ZIP Compressed (zipped) Folder Yes
SEEK.$$$ $$$ File No
SEEK.BAT MS-DOS Batch File Yes
SEEK.VBS VBScript Script File Yes
For those, it suffices to test, case-dependently, whether the Extension
appears as a word in the Type : if it does not do so, then the file must
be a known Type. But the converse is only reliable if one can be sure
that a known extension cannot ever, in any natural language, occur as a
word in the corresponding Type string.
Consider the possibility of a default browser being called "View Your
HTML", for example - unlikely, but possible. Or that of a file with
extension "File".
The application is SEAKFYLE, via
<http://www.merlyn.demon.co.uk/programs/32-bit/00index.htm>, using
Options X3 and X4. The current code is in a paragraph currently starting
at Line 281 :
if (Eggs == 3 || Eggs == 4) { S = Item.Path
S = S.substring(S.lastIndexOf(".") + 1) // Extn
if (Eggs == 4 ^ new RegExp("\\b"+S+"\\b").test(Item.Type)) return }
Eggs 3 returns for unknown types; Eggs 4 for known ones. In JScript,
the token ^ means "Exclusive-Or".
--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; WinXP.
Web <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links.
PAS EXE TXT ZIP via <http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; WinXP.
Web <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links.
PAS EXE TXT ZIP via <http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.