Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #9898 > unrolled thread

JScript - is a file of a known Type?

Started byDr J R Stockton <reply1201@merlyn.demon.co.uk>
First post2012-01-03 17:09 +0000
Last post2012-01-07 20:11 +0000
Articles 20 on this page of 31 — 9 participants

Back to article view | Back to comp.lang.javascript


Contents

  JScript - is a file of a known Type? Dr J R Stockton <reply1201@merlyn.demon.co.uk> - 2012-01-03 17:09 +0000
    Re: JScript - is a file of a known Type? "Mayayana" <mayayana@invalid.nospam> - 2012-01-03 21:13 -0500
      Re: JScript - is a file of a known Type? Todd Vargo <tlvargo@sbcglobal.netz> - 2012-01-04 00:55 -0500
        Re: JScript - is a file of a known Type? "Mayayana" <mayayana@invalid.nospam> - 2012-01-04 09:18 -0500
          Re: JScript - is a file of a known Type? "Dave \"Crash\" Dummy" <invalid@invalid.invalid> - 2012-01-04 09:40 -0500
            Re: JScript - is a file of a known Type? "Mayayana" <mayayana@invalid.nospam> - 2012-01-04 10:23 -0500
              Re: JScript - is a file of a known Type? Todd Vargo <tlvargo@sbcglobal.netz> - 2012-01-04 20:22 -0500
              Re: JScript - is a file of a known Type? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-01-05 22:01 -0800
                Re: JScript - is a file of a known Type? John G Harris <john@nospam.demon.co.uk> - 2012-01-06 11:04 +0000
                  Re: JScript - is a file of a known Type? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-01-06 04:26 -0800
                    Re: JScript - is a file of a known Type? John G Harris <john@nospam.demon.co.uk> - 2012-01-06 14:58 +0000
                      Re: JScript - is a file of a known Type? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-01-06 12:27 -0800
                Re: JScript - is a file of a known Type? Dr J R Stockton <reply1201@merlyn.demon.co.uk> - 2012-01-07 21:54 +0000
            JScript - WScript output similar to CScript output> Dr J R Stockton <reply1201@merlyn.demon.co.uk> - 2012-01-05 20:29 +0000
              Re: JScript - WScript output similar to CScript output> "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-01-05 22:05 -0800
                Re: JScript - WScript output similar to CScript output> Bwig Zomberi <zomberiMAPSONNOSPAM@gmail.invalid> - 2012-01-06 14:31 +0530
                  Re: JScript - WScript output similar to CScript output> Dr J R Stockton <reply1201@merlyn.demon.co.uk> - 2012-01-07 21:14 +0000
                Re: JScript - WScript output similar to CScript output> Dr J R Stockton <reply1201@merlyn.demon.co.uk> - 2012-01-07 21:10 +0000
                  Re: JScript - WScript output similar to CScript output> "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-01-08 14:52 -0800
                    Re: JScript - WScript output similar to CScript output> Dr J R Stockton <reply1202@merlyn.demon.co.uk> - 2012-01-09 23:45 +0000
                      Re: JScript - WScript output similar to CScript output> Todd Vargo <tlvargo@sbcglobal.netz> - 2012-01-10 00:27 -0500
                      Re: JScript - WScript output similar to CScript output> Dr J R Stockton <J.R.Stockton@physics.org> - 2012-01-10 13:40 -0800
                        Re: JScript - WScript output similar to CScript output> "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-01-10 17:04 -0800
                          Re: JScript - WScript output similar to CScript output> Dr J R Stockton <reply1202@merlyn.demon.co.uk> - 2012-01-12 23:43 +0000
                            Re: JScript - WScript output similar to CScript output> "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-01-12 22:36 -0800
                            Re: JScript - WScript output similar to CScript output> "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-01-12 22:47 -0800
                              Re: JScript - WScript output similar to CScript output> Dr J R Stockton <J.R.Stockton@physics.org> - 2012-01-14 12:15 -0800
              Re: JScript - WScript output similar to CScript output> Bwig Zomberi <zomberiMAPSONNOSPAM@gmail.invalid> - 2012-01-06 14:43 +0530
              Re: JScript - WScript output similar to CScript output> Todd Vargo <tlvargo@sbcglobal.netz> - 2012-01-06 05:20 -0500
                Re: JScript - WScript output similar to CScript output> "Mayayana" <mayayana@invalid.nospam> - 2012-01-06 08:33 -0500
                  Re: JScript - WScript output similar to CScript output> Dr J R Stockton <reply1201@merlyn.demon.co.uk> - 2012-01-07 20:11 +0000

Page 1 of 2  [1] 2  Next page →


#9898 — JScript - is a file of a known Type?

FromDr J R Stockton <reply1201@merlyn.demon.co.uk>
Date2012-01-03 17:09 +0000
SubjectJScript - is a file of a known Type?
Message-ID<3wJilUEcZzAPFwTs@invalid.uk.co.demon.merlyn.invalid>
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".

-- 
 (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.

[toc] | [next] | [standalone]


#9904

From"Mayayana" <mayayana@invalid.nospam>
Date2012-01-03 21:13 -0500
Message-ID<je0ce6$3q1$1@dont-email.me>
In reply to#9898
I'm not sure I understand. Do you mean you want to
find out if it's a registered file type? That would be
in HKCR. If OK6 is registered there will be a key
HKCR\.ok6


-- 
--
"Dr J R Stockton" <reply1201@merlyn.demon.co.uk> wrote in message 
news:3wJilUEcZzAPFwTs@invalid.uk.co.demon.merlyn.invalid...
|
| 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".
|
| -- 
| (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. 

[toc] | [prev] | [next] | [standalone]


#9905

FromTodd Vargo <tlvargo@sbcglobal.netz>
Date2012-01-04 00:55 -0500
Message-ID<je0plc$u6g$1@news.albasani.net>
In reply to#9904
On 1/3/2012 9:13 PM, Mayayana wrote:
> I'm not sure I understand. Do you mean you want to
> find out if it's a registered file type? That would be
> in HKCR. If OK6 is registered there will be a key
> HKCR\.ok6

Correct. However getting the string for the file type requires a bit 
more effort. Some extensions have their type in the default string. 
While others provide the name to another key where the real string must 
be read.

For example, on my system the default string for .bmp is Paint.Picture 
which you then find there is an Paint.Picture key where you find the 
file type is "Bitmap Image".

And some, like .x, store the type in a string named "PerceivedType".

-- 
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

[toc] | [prev] | [next] | [standalone]


#9915

From"Mayayana" <mayayana@invalid.nospam>
Date2012-01-04 09:18 -0500
Message-ID<je1mtu$50r$1@dont-email.me>
In reply to#9905
I'm still not sure I get what Dr J R Stockton is after,
but the Registry system is straightforward.

HKCR\.txt default value: "txtfile"
HKCR\txtfile default value: "Text Document"

PerceivedType is not related to file registration. According
to MS it's actually meant to be used with Windows
Find/Search.
http://msdn.microsoft.com/en-us/library/aa965719%28v=vs.85%29.aspx

  Unless someone is building a shell view I don't see the
point of needing the file type's class name. The only need for
that in the first place is so that the way of looking up files
can work despite changes: If Firefox takes over .html from IE,
or IE changes it back, the current status can still be tracked
via HKCR\.html.

The existence of HKCR\.txt confirms that it's a registered type.
The HKCR\[extension key default value] (HKCR\txtfile\) subkeys
then provide other information, like icon, default program for
that file type, etc.

  I see what you mean about .x. I wonder how such a key got
written in the first place. It doesn't have any purpose that I
can see. I have very few of those in my Registry. The only
thing I can guess is that some uninstallers remove the default
value for a program's extensions during uninstall but don't
remove the extension key itself.

 In any case, it doesn't change the design. "Text" is
not a registered file type. .x is not really registered. So I
guess I should amend what I said above: To be thorough
one should confirm there's a default program for a file type,
under:
HKCR\[extension key default value]\shell\open\command\

  That gets back to why anyone cares about the registered
file type name in the first place. Usually the point of looking
up this info. is to find the default program.


-- 
--
"Todd Vargo" <tlvargo@sbcglobal.netz> wrote in message 
news:je0plc$u6g$1@news.albasani.net...
| On 1/3/2012 9:13 PM, Mayayana wrote:
| > I'm not sure I understand. Do you mean you want to
| > find out if it's a registered file type? That would be
| > in HKCR. If OK6 is registered there will be a key
| > HKCR\.ok6
|
| Correct. However getting the string for the file type requires a bit
| more effort. Some extensions have their type in the default string.
| While others provide the name to another key where the real string must
| be read.
|
| For example, on my system the default string for .bmp is Paint.Picture
| which you then find there is an Paint.Picture key where you find the
| file type is "Bitmap Image".
|
| And some, like .x, store the type in a string named "PerceivedType".
|
| -- 
| Todd Vargo
| (Post questions to group only. Remove "z" to email personal messages) 

[toc] | [prev] | [next] | [standalone]


#9916

From"Dave \"Crash\" Dummy" <invalid@invalid.invalid>
Date2012-01-04 09:40 -0500
Message-ID<je1ocf$e6m$1@dont-email.me>
In reply to#9915
Mayayana wrote:
> I'm still not sure I get what Dr J R Stockton is after, but the
> Registry system is straightforward.
> 
> HKCR\.txt default value: "txtfile" HKCR\txtfile default value: "Text
> Document"
> 
> PerceivedType is not related to file registration. According to MS
> it's actually meant to be used with Windows Find/Search. 
> http://msdn.microsoft.com/en-us/library/aa965719%28v=vs.85%29.aspx
> 
> Unless someone is building a shell view I don't see the point of
> needing the file type's class name. The only need for that in the
> first place is so that the way of looking up files can work despite
> changes: If Firefox takes over .html from IE, or IE changes it back,
> the current status can still be tracked via HKCR\.html.
> 
> The existence of HKCR\.txt confirms that it's a registered type. The
> HKCR\[extension key default value] (HKCR\txtfile\) subkeys then
> provide other information, like icon, default program for that file
> type, etc.
> 
> I see what you mean about .x. I wonder how such a key got written in
> the first place. It doesn't have any purpose that I can see. I have
> very few of those in my Registry. The only thing I can guess is that
> some uninstallers remove the default value for a program's extensions
> during uninstall but don't remove the extension key itself.
> 
> In any case, it doesn't change the design. "Text" is not a registered
> file type. .x is not really registered. So I guess I should amend
> what I said above: To be thorough one should confirm there's a
> default program for a file type, under: HKCR\[extension key default
> value]\shell\open\command\
> 
> That gets back to why anyone cares about the registered file type
> name in the first place. Usually the point of looking up this info.
> is to find the default program.

The trouble with "file type" as stored in the registry and read by
"objFile.type" is that it can be and often is changed by applications. For
example, on my computer the ".bmp" file mentioned above is a "Paint Shop
Pro 5 Image," not a "Paint.Picture."
-- 
Crash

Today is the first day of the rest of your life, and there's not a
damned thing you can do about it.

[toc] | [prev] | [next] | [standalone]


#9917

From"Mayayana" <mayayana@invalid.nospam>
Date2012-01-04 10:23 -0500
Message-ID<je1qn9$t3u$1@dont-email.me>
In reply to#9916
|
| The trouble with "file type" as stored in the registry and read by
| "objFile.type" is that it can be and often is changed by applications. For
| example, on my computer the ".bmp" file mentioned above is a "Paint Shop
| Pro 5 Image," not a "Paint.Picture."

  Yes, but that's the whole point. That name is only
a pointer to the Registry key that holds the relevant info.
about a registered file, such as the path to the default
program to open it. The file class name itself is not
significant. It's a pointer.

  I guess a distinction should be made between the
two "file type" values. I've never used objFile.type
and don't see any point to it, so I'm not sure what
it shows.

  I'll call the default value of HKCR\.xxx the file class
name. (I don't know if there's an official term.) I'll call
the default value of HKCR\[FileClassName] the file type
name. So:

HKCR\.txt   default value:    txtfile
HKCR\txtfile  default value:  Text Document

  Any program that gets assigned as the default for a
file type can set any values it wants. Those values are
really only for Registry navigation and advertising. (Since
most software is commercial one often gets commercial
names.) For .bmp I have a file class name of "IrfanView.BMP"
and a file type name of "IrfanView BMP File". Neither of
those names tells me anything about what a BMP file is.
If I wanted a script to provide useful information about
file types, perhaps in an HTA, I think I'd write a function
to return strings like "text file", "cascading style sheet file",
"webpage file", etc. There simply isn't any standard like
that in Windows.

[toc] | [prev] | [next] | [standalone]


#9921

FromTodd Vargo <tlvargo@sbcglobal.netz>
Date2012-01-04 20:22 -0500
Message-ID<je2u10$3ju$1@news.albasani.net>
In reply to#9917
On 1/4/2012 10:23 AM, Mayayana wrote:
> |
> | The trouble with "file type" as stored in the registry and read by
> | "objFile.type" is that it can be and often is changed by applications. For
> | example, on my computer the ".bmp" file mentioned above is a "Paint Shop
> | Pro 5 Image," not a "Paint.Picture."
>
>    Yes, but that's the whole point. That name is only
> a pointer to the Registry key that holds the relevant info.
> about a registered file, such as the path to the default
> program to open it. The file class name itself is not
> significant. It's a pointer.
>
>    I guess a distinction should be made between the
> two "file type" values. I've never used objFile.type
> and don't see any point to it, so I'm not sure what
> it shows.
>
>    I'll call the default value of HKCR\.xxx the file class
> name. (I don't know if there's an official term.) I'll call
> the default value of HKCR\[FileClassName] the file type
> name. So:
>
> HKCR\.txt   default value:    txtfile
> HKCR\txtfile  default value:  Text Document
>
>    Any program that gets assigned as the default for a
> file type can set any values it wants. Those values are
> really only for Registry navigation and advertising. (Since
> most software is commercial one often gets commercial
> names.) For .bmp I have a file class name of "IrfanView.BMP"
> and a file type name of "IrfanView BMP File". Neither of
> those names tells me anything about what a BMP file is.
> If I wanted a script to provide useful information about
> file types, perhaps in an HTA, I think I'd write a function
> to return strings like "text file", "cascading style sheet file",
> "webpage file", etc. There simply isn't any standard like
> that in Windows.

I know what you mean. It drives me nuts when installers hijack 
registered file associations without warning. It has gotten better over 
the years with installers offering the option to select or exclude 
taking over existing extensions. I have added many custom keys over the 
years to select from several apps with special parameters for particular 
extensions. So when these misbehaved installers hijack one of these on 
me, you know I'm not a happy camper.

-- 
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

[toc] | [prev] | [next] | [standalone]


#9944

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2012-01-05 22:01 -0800
Message-ID<4924e3fd-a25a-4cbe-8410-6f1c7f6984e4@r5g2000yqc.googlegroups.com>
In reply to#9917
On Jan 3, 11:09 am, Dr J R Stockton <reply1...@merlyn.demon.co.uk>
wrote:
> 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?

Generally not as there is not a bijection between the TYPE and its
registry entry. One would have to use the file extension as a key to
lookup the existence of an entry to get more accurate results.

> 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

Here is some code that creates a similar result on my machine:

<https://gist.github.com/1569247>

[toc] | [prev] | [next] | [standalone]


#9960

FromJohn G Harris <john@nospam.demon.co.uk>
Date2012-01-06 11:04 +0000
Message-ID<C4l0seGmUtBPFwcT@J.A830F0FF37FB96852AD08924D9443D28E23ED5CD>
In reply to#9944
On Thu, 5 Jan 2012 at 22:01:48, in comp.lang.javascript, Michael Haufe
(TNO) wrote:
>On Jan 3, 11:09 am, Dr J R Stockton <reply1...@merlyn.demon.co.uk>
>wrote:
>> 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?
>
>Generally not as there is not a bijection between the TYPE and its
>registry entry. One would have to use the file extension as a key to
>lookup the existence of an entry to get more accurate results.
  <snip>

Beware of believing file extensions. Up to Win ME at least, I haven't
checked XP, a .txt file's content is inspected by Windows. If it looks
like a PIF file then the file will be executed when you thought it would
be displayed by Notepad.

  John
-- 
John Harris

[toc] | [prev] | [next] | [standalone]


#9976

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2012-01-06 04:26 -0800
Message-ID<09c6d38b-69ba-4e49-8b42-a18992468aba@o9g2000yqa.googlegroups.com>
In reply to#9960
On Jan 6, 5:04 am, John G Harris <j...@nospam.demon.co.uk> wrote:
> On Thu, 5 Jan 2012 at 22:01:48, in comp.lang.javascript, Michael Haufe(TNO) wrote:
> >On Jan 3, 11:09 am, Dr J R Stockton <reply1...@merlyn.demon.co.uk>
> >wrote:
> >> 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?
>
> >Generally not as there is not a bijection between the TYPE and its
> >registry entry. One would have to use the file extension as a key to
> >lookup the existence of an entry to get more accurate results.
>
>   <snip>
>
> Beware of believing file extensions. Up to Win ME at least, I haven't
> checked XP, a .txt file's content is inspected by Windows. If it looks
> like a PIF file then the file will be executed when you thought it would
> be displayed by Notepad.

Whether it is an _expected_ result or not is a separate issue to
whether it is KNOWN/Recognized by the OS.

[toc] | [prev] | [next] | [standalone]


#9978

FromJohn G Harris <john@nospam.demon.co.uk>
Date2012-01-06 14:58 +0000
Message-ID<4eExnaBlwwBPFwIz@J.A830F0FF37FB96852AD08924D9443D28E23ED5CD>
In reply to#9976
On Fri, 6 Jan 2012 at 04:26:46, in comp.lang.javascript, Michael Haufe
(TNO) wrote:
>On Jan 6, 5:04 am, John G Harris <j...@nospam.demon.co.uk> wrote:
>> On Thu, 5 Jan 2012 at 22:01:48, in comp.lang.javascript, Michael
>>Haufe(TNO) wrote:
>> >On Jan 3, 11:09 am, Dr J R Stockton <reply1...@merlyn.demon.co.uk>
>> >wrote:
>> >> 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?
>>
>> >Generally not as there is not a bijection between the TYPE and its
>> >registry entry. One would have to use the file extension as a key to
>> >lookup the existence of an entry to get more accurate results.
>>
>>   <snip>
>>
>> Beware of believing file extensions. Up to Win ME at least, I haven't
>> checked XP, a .txt file's content is inspected by Windows. If it looks
>> like a PIF file then the file will be executed when you thought it would
>> be displayed by Notepad.
>
>Whether it is an _expected_ result or not is a separate issue to
>whether it is KNOWN/Recognized by the OS.

But if you "use the file extension as a key to lookup the existence of
an entry to get more accurate results" then you will get *less* accurate
results in this case. That's the point. Not getting the action you
expected is merely the evidence.

  John
-- 
John Harris

[toc] | [prev] | [next] | [standalone]


#9992

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2012-01-06 12:27 -0800
Message-ID<e5f8a486-1f3a-4770-8d70-85bd23ceca56@u20g2000yqb.googlegroups.com>
In reply to#9978
On Jan 6, 8:58 am, John G Harris <j...@nospam.demon.co.uk> wrote:
> On Fri, 6 Jan 2012 at 04:26:46, in comp.lang.javascript, Michael Haufe
> (TNO) wrote:
> >On Jan 6, 5:04 am, John G Harris <j...@nospam.demon.co.uk> wrote:
> >> On Thu, 5 Jan 2012 at 22:01:48, in comp.lang.javascript, Michael
> >>Haufe(TNO) wrote:
> >> >On Jan 3, 11:09 am, Dr J R Stockton <reply1...@merlyn.demon.co.uk>
> >> >wrote:
> >> >> 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?
>
> >> >Generally not as there is not a bijection between the TYPE and its
> >> >registry entry. One would have to use the file extension as a key to
> >> >lookup the existence of an entry to get more accurate results.
>
> >>   <snip>
>
> >> Beware of believing file extensions. Up to Win ME at least, I haven't
> >> checked XP, a .txt file's content is inspected by Windows. If it looks
> >> like a PIF file then the file will be executed when you thought it would
> >> be displayed by Notepad.
>
> >Whether it is an _expected_ result or not is a separate issue to
> >whether it is KNOWN/Recognized by the OS.
>
> But if you "use the file extension as a key to lookup the existence of
> an entry to get more accurate results" then you will get *less* accurate
> results in this case. That's the point. Not getting the action you
> expected is merely the evidence.

Since the original question, AFAICT, was to determine whether the OS
recognizes a given file, moving from a human interpretation of the
file's description to an existence check in the registry is most
definitely going to be more accurate. If I have a predicate: isKnown,
and isKnown("*.dat") is true, it doesn't matter at this level of
abstraction what application that extension is mapped to, only whether
it has a mapping at all.

[toc] | [prev] | [next] | [standalone]


#10028

FromDr J R Stockton <reply1201@merlyn.demon.co.uk>
Date2012-01-07 21:54 +0000
Message-ID<0q7CDMOe8LCPFwj2@invalid.uk.co.demon.merlyn.invalid>
In reply to#9944
In comp.lang.javascript message <4924e3fd-a25a-4cbe-8410-6f1c7f6984e4@r5
g2000yqc.googlegroups.com>, Thu, 5 Jan 2012 22:01:48, "Michael Haufe
(TNO)" <tno@thenewobjective.com> posted:

>On Jan 3, 11:09 am, Dr J R Stockton <reply1...@merlyn.demon.co.uk>
>wrote:
>> 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?
>
>Generally not as there is not a bijection between the TYPE and its
>registry entry. One would have to use the file extension as a key to
>lookup the existence of an entry to get more accurate results.

Well, the extension can be obtained from the File Object, and the method
in the code that you cite is certainly direct enough.  All I need do is
to take your try/catch and adapt it for the target context, in
<http://www.merlyn.demon.co.uk.programs/32-bit/seakfyle.js>.

You have a habit, I think, of getting to the core of the matter and
giving an appropriate answer.

>Here is some code that creates a similar result on my machine:
>
><https://gist.github.com/1569247>

Hence, installed and working,

        function Haufe(It) {
          var fName = It.Name,
            ext = fName.slice(fName.lastIndexOf(".")).toLowerCase()
          try { WshShell.RegRead("HKCR\\"+ext+"\\") ; return true }
          catch(e) { return false }
          }

However, it returns true for extension $$$, which needs thinking about.

Also, your way of getting the extension is eleven characters shorter
than what I had.

Thanks.

-- 
 (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk  Turnpike 6.05  WinXP.
 Web  <http://www.merlyn.demon.co.uk/> - FAQ-type topics, acronyms, and links.
 Command-prompt MiniTrue is useful for viewing/searching/altering files. Free,
 DOS/Win/UNIX now 2.0.6; see <URL:http://www.merlyn.demon.co.uk/pc-links.htm>.

[toc] | [prev] | [next] | [standalone]


#9940 — JScript - WScript output similar to CScript output>

FromDr J R Stockton <reply1201@merlyn.demon.co.uk>
Date2012-01-05 20:29 +0000
SubjectJScript - WScript output similar to CScript output>
Message-ID<BgivRqI0ggBPFwNs@invalid.uk.co.demon.merlyn.invalid>
In reply to#9916
In comp.lang.javascript message <je1ocf$e6m$1@dont-email.me>, Wed, 4 Jan
2012 09:40:15, "Dave \"Crash\" Dummy" <invalid@invalid.invalid> posted:

>
>The trouble with "file type" as stored in the registry and read by
>"objFile.type" is that it can be and often is changed by applications. For
>example, on my computer the ".bmp" file mentioned above is a "Paint
>Shop
>Pro 5 Image," not a "Paint.Picture."

The fact that the Type string can be changed provides a good reason for
having a convenient way to read the Type string.

Typically, MS make it harder to tell by code whether a file's Type is
known or not by putting an uninformative but readable string where they
could more easily have put an empty string or a recognisable language-
independent one such as "-".

No-one has actually answered the question.



Let's try another.

The CScript in question is started from the DOS-box command-line and
writes lines to the screen - it would run perfectly well on an ASR33
teletype.  At present, if started in WScript, it exits leaving a small
note.

It would be nice to allow execution by WScript, with GUI output; but, to
be worth doing, it would be necessary for there to be an easy way of
creating and writing (line by line) to something resembling an HTML
textarea.  Is that available, and if so how is it done or where do I
need to look?


-- 
 (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 & 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.

[toc] | [prev] | [next] | [standalone]


#9945 — Re: JScript - WScript output similar to CScript output>

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2012-01-05 22:05 -0800
SubjectRe: JScript - WScript output similar to CScript output>
Message-ID<847ebf0b-4938-4a1e-a108-964535d3d853@z12g2000yqm.googlegroups.com>
In reply to#9940
On Jan 5, 2:29 pm, Dr J R Stockton <reply1...@merlyn.demon.co.uk>
wrote:

> The CScript in question is started from the DOS-box command-line and
> writes lines to the screen - it would run perfectly well on an ASR33
> teletype.  At present, if started in WScript, it exits leaving a small
> note.
>
> It would be nice to allow execution by WScript, with GUI output; but, to
> be worth doing, it would be necessary for there to be an easy way of
> creating and writing (line by line) to something resembling an HTML
> textarea.  Is that available, and if so how is it done or where do I
> need to look?

Are you looking for a formatted table output in the command window in
a way similar to your original example?

[toc] | [prev] | [next] | [standalone]


#9953 — Re: JScript - WScript output similar to CScript output>

FromBwig Zomberi <zomberiMAPSONNOSPAM@gmail.invalid>
Date2012-01-06 14:31 +0530
SubjectRe: JScript - WScript output similar to CScript output>
Message-ID<je6cri$v7v$1@speranza.aioe.org>
In reply to#9945
Michael Haufe (TNO) wrote:
> On Jan 5, 2:29 pm, Dr J R Stockton<reply1...@merlyn.demon.co.uk>
> wrote:
>
>> The CScript in question is started from the DOS-box command-line and
>> writes lines to the screen - it would run perfectly well on an ASR33
>> teletype.  At present, if started in WScript, it exits leaving a small
>> note.

Are you looking for the /nologo parameter to cscript?


-- 
Bwig Zomberi

[toc] | [prev] | [next] | [standalone]


#10027 — Re: JScript - WScript output similar to CScript output>

FromDr J R Stockton <reply1201@merlyn.demon.co.uk>
Date2012-01-07 21:14 +0000
SubjectRe: JScript - WScript output similar to CScript output>
Message-ID<JrtdjVLGXLCPFwEl@invalid.uk.co.demon.merlyn.invalid>
In reply to#9953
In comp.lang.javascript message <je6cri$v7v$1@speranza.aioe.org>, Fri, 6
Jan 2012 14:31:26, Bwig Zomberi <zomberiMAPSONNOSPAM@gmail.invalid>
posted:

>Michael Haufe (TNO) wrote:
>> On Jan 5, 2:29 pm, Dr J R Stockton<reply1...@merlyn.demon.co.uk>
>> wrote:
>>
>>> The CScript in question is started from the DOS-box command-line and
>>> writes lines to the screen - it would run perfectly well on an ASR33
>>> teletype.  At present, if started in WScript, it exits leaving a small
>>> note.
>
>Are you looking for the /nologo parameter to cscript?

I do not suppose Michael Haufe is; and I am not, especially as it needs
to be //nologo.  I know it well.

-- 
(c) John Stockton, nr London UK.  ???@merlyn.demon.co.uk  Turnpike v6.05  MIME.
 Web  <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
     Check boilerplate spelling -- error is a public sign of incompetence.
    Never fully trust an article from a poster who gives no full real name.

[toc] | [prev] | [next] | [standalone]


#10026 — Re: JScript - WScript output similar to CScript output>

FromDr J R Stockton <reply1201@merlyn.demon.co.uk>
Date2012-01-07 21:10 +0000
SubjectRe: JScript - WScript output similar to CScript output>
Message-ID<dbkY$XKhTLCPFwFa@invalid.uk.co.demon.merlyn.invalid>
In reply to#9945
In comp.lang.javascript message <847ebf0b-4938-4a1e-a108-964535d3d853@z1
2g2000yqm.googlegroups.com>, Thu, 5 Jan 2012 22:05:53, "Michael Haufe
(TNO)" <tno@thenewobjective.com> posted:

>On Jan 5, 2:29 pm, Dr J R Stockton <reply1...@merlyn.demon.co.uk>
>wrote:
>
>> The CScript in question is started from the DOS-box command-line and
>> writes lines to the screen - it would run perfectly well on an ASR33
>> teletype.  At present, if started in WScript, it exits leaving a small
>> note.
>>
>> It would be nice to allow execution by WScript, with GUI output; but, to
>> be worth doing, it would be necessary for there to be an easy way of
>> creating and writing (line by line) to something resembling an HTML
>> textarea.  Is that available, and if so how is it done or where do I
>> need to look?
>
>Are you looking for a formatted table output in the command window in
>a way similar to your original example?

Yes.

The original article in the thread was concerned with one particular
point.  That example was partly from what I already have, with the third
column by hand.  It will be to produce something similar but with other
information.

But the core of the situation is that all CScript output is through

        function Right(N, Str) { N = Hush[N]
          if (N == "0") return
          if (N == "1") WScript.StdOut.Write(Str)
          if (N == "2") WScript.StdErr.Write(Str)
          if (N == "3") txtStreamOut.Write(Str)
          }

in which almost all Str end with a newline; and I want to use

          if (N == "4") SOMETHING(Str)

[ after having detected (which I can do) WScript ] to get a
corresponding display.

If that can be done, the application is no longer just a CScript
application usable only by those who can find and use a DOS-like command
line, but it is usable also by those who only use GUI routines.


Another approach would be to use the same code in an HTA, which I would
have to learn about.

-- 
 (c) John Stockton, nr London, UK.    ?@merlyn.demon.co.uk     Turnpike v6.05.
 Website  <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
 PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm
 Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.

[toc] | [prev] | [next] | [standalone]


#10059 — Re: JScript - WScript output similar to CScript output>

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2012-01-08 14:52 -0800
SubjectRe: JScript - WScript output similar to CScript output>
Message-ID<a46fb17c-5638-4b1a-8d87-034ca257435e@p16g2000yqd.googlegroups.com>
In reply to#10026
On Jan 7, 3:10 pm, Dr J R Stockton <reply1...@merlyn.demon.co.uk>
wrote:
> In comp.lang.javascript message <847ebf0b-4938-4a1e-a108-964535d3d853@z1
> 2g2000yqm.googlegroups.com>, Thu, 5 Jan 2012 22:05:53, "Michael Haufe
> (TNO)" <t...@thenewobjective.com> posted:
>
> >Are you looking for a formatted table output in the command window in
> >a way similar to your original example?
>
> Yes.
>
> The original article in the thread was concerned with one particular
> point.  That example was partly from what I already have, with the third
> column by hand.  It will be to produce something similar but with other
> information.

So did my sample code work help at all?

> But the core of the situation is that all CScript output is through
>
>         function Right(N, Str) { N = Hush[N]
>           if (N == "0") return
>           if (N == "1") WScript.StdOut.Write(Str)
>           if (N == "2") WScript.StdErr.Write(Str)
>           if (N == "3") txtStreamOut.Write(Str)
>           }
>
> in which almost all Str end with a newline; and I want to use
>
>           if (N == "4") SOMETHING(Str)
>
> [ after having detected (which I can do) WScript ] to get a
> corresponding display.
>
> If that can be done, the application is no longer just a CScript
> application usable only by those who can find and use a DOS-like command
> line, but it is usable also by those who only use GUI routines.

So to check if I understand correctly, you want a function that will
take a collection of results in the format of:

FILENAME                TYPE                            KNOWN

and display them as a formatted table in CScript or as an HTML table
in a generated HTA in WScript?

[toc] | [prev] | [next] | [standalone]


#10097 — Re: JScript - WScript output similar to CScript output>

FromDr J R Stockton <reply1202@merlyn.demon.co.uk>
Date2012-01-09 23:45 +0000
SubjectRe: JScript - WScript output similar to CScript output>
Message-ID<X9E62zggw3CPFwnp@invalid.uk.co.demon.merlyn.invalid>
In reply to#10059
In comp.lang.javascript message <a46fb17c-5638-4b1a-8d87-034ca257435e@p1
6g2000yqd.googlegroups.com>, Sun, 8 Jan 2012 14:52:24, "Michael Haufe
(TNO)" <tno@thenewobjective.com> posted:

>On Jan 7, 3:10 pm, Dr J R Stockton <reply1...@merlyn.demon.co.uk>
>wrote:
>> In comp.lang.javascript message <847ebf0b-4938-4a1e-a108-964535d3d853@z1
>> 2g2000yqm.googlegroups.com>, Thu, 5 Jan 2012 22:05:53, "Michael Haufe
>> (TNO)" <t...@thenewobjective.com> posted:
>>
>> >Are you looking for a formatted table output in the command window in
>> >a way similar to your original example?
>>
>> Yes.
>>
>> The original article in the thread was concerned with one particular
>> point.  That example was partly from what I already have, with the third
>> column by hand.  It will be to produce something similar but with other
>> information.
>
>So did my sample code work help at all?

Completely.  But with the apparent peculiarity that extension $$$ (my
editor's backup) is known to the registry, although the corresponding
.Type string is "$$$ File", similar to that for a file with extension
OK4 which is not so known.

Aside to non-Anglos :
        What would the .Type property be for an unregistered file in
        systems set for other well-known Western European languages?
        E.g. Fichier OK4 / OK4 Fichier, etc.?  Users are required to be
        able to read instructions in English, but should not be required
        to have an English-speaking Windows.


>> But the core of the situation is that all CScript output is through
>>
>>         function Right(N, Str) { N = Hush[N]
>>           if (N == "0") return
>>           if (N == "1") WScript.StdOut.Write(Str)
>>           if (N == "2") WScript.StdErr.Write(Str)
>>           if (N == "3") txtStreamOut.Write(Str)
>>           }
>>
>> in which almost all Str end with a newline; and I want to use
>>
>>           if (N == "4") SOMETHING(Str)
>>
>> [ after having detected (which I can do) WScript ] to get a
>> corresponding display.
>>
>> If that can be done, the application is no longer just a CScript
>> application usable only by those who can find and use a DOS-like command
>> line, but it is usable also by those who only use GUI routines.
>
>So to check if I understand correctly, you want a function that will
>take a collection of results in the format of:
>
>FILENAME                TYPE                            KNOWN
>
>and display them as a formatted table in CScript or as an HTML table
>in a generated HTA in WScript?

Not really; you are going further that I wish for.

I wanted a routine that would accept text, a line at a time (P.S. to be
strictly accurate, these lines could contain newlines), and cause it to
appear as it would in Notepad.  The example is tabular, but other lines
are not.  To illustrate, here's a command-prompt screen capture :

prompt>seek . n
  :: SEAKFYLE.JS >= 2012-01-09, at 2012-01-09 20:21:56, see SEAKFYLE.HTM
 2012-01-09 17:40:34        33275 .....a.. "SEAKFYLE.$$$"
 2012-01-09 17:41:00        33291 .....a.. "SEAKFYLE.HTM"
 2012-01-09 17:38:37        17603 .....a.. "SEAKFYLE.JS"
| Date/time now : 2012-01-09 20:21:56
| Find : 3 matches
| Finding in : C:\WSH\SEEK ; 31 ms


If I do the following command line, nothing appears in the screen before
the next prompt, as Q sets all output to Channel 3 which is sent To file
xyz.

        prompt>seek . n Q333333 Txyz

and file xyz. can be opened in Notepad (except for needing an 0D before
each 0A, which can be dealt with (most easily by using WFVIEW instead)).

Aside : AFAICS, no GUI editor or viewer that I have can AFAIK accept
        piped-in text, which is a pity.

What I want to end up with is using essentially the same code as I have
at present, but as a GUI application - instead of opening a Command
Prompt and giving it a Command Line, to open a GUI window and give it,
with some equivalent of a JavaScript prompt(), the commands.  Or just
command-line in, GUI out.

I forgot to say that the GUI needs to show each line as it is output
from the current code, without waiting for the stream to complete.

The alternative seems to be to use an HTA, treating my existing code as
an include file of functions and variables, and suppressing any unwanted
parts.  That should be easy, if I learn about HTAs first - - - which I
seem to have done.

It's now fundamentally working in an HTA, but the adapting needs to be
cleaned up, though not tonight.

-- 
 (c) John Stockton, nr London, UK.    ?@merlyn.demon.co.uk     Turnpike v6.05.
 Website  <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
 PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm
 Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.javascript


csiph-web