Directory listing on localhost

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ravi

    Directory listing on localhost

    I am new to scripting. I am looking for a way to find a filename in a
    directory using regular expressions. I do not have a client-server setup
    i.e. the directory that I want to search in is local (the same directory
    in which the script resides). What functions are used to list one by one
    the files in a directory so that I may match the filename with a regular
    expression (say to find all files which begin with profile_5). Any
    suggestions/pointers will be highly welcome.
    Thank you for your help.

  • kaeli

    #2
    Re: Directory listing on localhost

    In article <bo8mfo$f9a$1@p rometheus.acsu. buffalo.edu>, rg27
    @cse.buffalo.ed u enlightened us with...[color=blue]
    > I am new to scripting. I am looking for a way to find a filename in a
    > directory using regular expressions. I do not have a client-server setup
    > i.e. the directory that I want to search in is local (the same directory
    > in which the script resides). What functions are used to list one by one
    > the files in a directory so that I may match the filename with a regular
    > expression (say to find all files which begin with profile_5). Any
    > suggestions/pointers will be highly welcome.
    > Thank you for your help.
    >
    >[/color]


    You can't with normal client-side javascript. ActiveX, WSH, or COM would
    (might) let you, browser-dependent and security allowing.

    What browser and OS are you using? Also, is this running on your
    machine, or a web server?


    -------------------------------------------------
    ~kaeli~
    Jesus saves, Allah protects, and Cthulhu
    thinks you'd make a nice sandwich.


    -------------------------------------------------

    Comment

    • Ravi

      #3
      Re: Directory listing on localhost

      kaeli wrote:
      [color=blue]
      > You can't with normal client-side javascript. ActiveX, WSH, or COM would
      > (might) let you, browser-dependent and security allowing.
      >
      > What browser and OS are you using? Also, is this running on your
      > machine, or a web server?[/color]

      Thank you for your reply. I am using Windows 2000 and IE6. The script is
      to be run on my machine. As an example say I have a file called
      display.html on my hard drive. When I load that file into the
      browser(using file:// in the address bar) I want to see a list of files
      which match a pattern (say beginning with abc) in the directory in which
      display.html resides. This directory is local. So basically I want the
      script to interact with the local filesystem and do some filename matching.

      Comment

      • Bill M.

        #4
        Re: Directory listing on localhost

        Try Perl


        Comment

        • kaeli

          #5
          Re: Directory listing on localhost

          In article <bo8pg7$jdp$1@p rometheus.acsu. buffalo.edu>, rg27
          @cse.buffalo.ed u enlightened us with...[color=blue]
          >
          > Thank you for your reply. I am using Windows 2000 and IE6. The script is
          > to be run on my machine. As an example say I have a file called
          > display.html on my hard drive. When I load that file into the
          > browser(using file:// in the address bar) I want to see a list of files
          > which match a pattern (say beginning with abc) in the directory in which
          > display.html resides. This directory is local. So basically I want the
          > script to interact with the local filesystem and do some filename matching.
          >
          >[/color]

          Oh, okay. Nope, not javascript. WSH (windows script host).

          Try this. Worked fine for me - IE6/Win2KPro.
          Set the folder to the one you want (i have wwwroot).
          If that works for you, you can modify it to do pattern matching and
          stuff. Look up WSH resources, as this is a javascript group. :)

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
          "http://www.w3.org/TR/REC-html40/loose.dtd">
          <html>
          <head>
          <title> New Document </title>
          </head>

          <body>
          <script language="vbscr ipt">
          'List Files in a particular Directory
          Dim fs2, f2, s2, folderspec2, strFileName2

          'Specify the path in which directory you want the list of files
          folderspec2 = "c:\inetpub\www root"

          Set fs2 = CreateObject("S cripting.FileSy stemObject")
          Set f2 = fs2.GetFolder(f olderspec2)

          For Each FileName In f2.files
          s2 = s2 & fileName.name
          s2 = s2 & "<br>"
          Next

          'Close all objects, set to nothing to free up memory.
          Document.Write s2
          set f2 = nothing
          set fs2 = nothing
          </script>
          </body>
          </html>

          --
          -------------------------------------------------
          ~kaeli~
          Jesus saves, Allah protects, and Cthulhu
          thinks you'd make a nice sandwich.


          -------------------------------------------------

          Comment

          • Lee

            #6
            Re: Directory listing on localhost

            kaeli said:[color=blue]
            >
            >In article <bo8pg7$jdp$1@p rometheus.acsu. buffalo.edu>, rg27
            >@cse.buffalo.e du enlightened us with...[color=green]
            >>
            >> Thank you for your reply. I am using Windows 2000 and IE6. The script is
            >> to be run on my machine. As an example say I have a file called
            >> display.html on my hard drive. When I load that file into the
            >> browser(using file:// in the address bar) I want to see a list of files
            >> which match a pattern (say beginning with abc) in the directory in which
            >> display.html resides. This directory is local. So basically I want the
            >> script to interact with the local filesystem and do some filename matching.
            >>
            >>[/color]
            >
            >Oh, okay. Nope, not javascript. WSH (windows script host).[/color]

            Actually, WSH understands Javascript (JScript), too.
            Here's an excerpt from one of my HTA's:

            <script type="text/javascript">
            var fso=new ActiveXObject(" Scripting.FileS ystemObject");

            function getScriptList(f olderspec){
            var f = fso.GetFolder(f olderspec);
            var fc = new Enumerator(f.fi les);
            for (; !fc.atEnd(); fc.moveNext()){
            var fileName=fc.ite m().Name
            if(-1!=fileName.sea rch(/^Install/)){
            // do stuff with filename beginning with "Install"
            }
            }
            }

            Comment

            • kaeli

              #7
              Re: Directory listing on localhost

              In article <bo8u6v011ul@dr n.newsguy.com>, REM0VElbspamtra p@cox.net
              enlightened us with...[color=blue]
              >
              > Actually, WSH understands Javascript (JScript), too.
              > Here's an excerpt from one of my HTA's:
              >[/color]


              Yeah, but this is running with no server with File-> Open.

              Can an HTA do that?
              I've never tried and I'm a bit of a newbie to HTAs. Too many Unix users
              here that use Netscape for it to be a valid work project. I just muck
              around with them a bit on my own computer.

              Your script looks like it should run with just a browser...does it?

              A bit OT, but what's the difference between an HTA and a WSH script, if
              any?

              -------------------------------------------------
              ~kaeli~
              Jesus saves, Allah protects, and Cthulhu
              thinks you'd make a nice sandwich.


              -------------------------------------------------

              Comment

              • Lee

                #8
                Re: Directory listing on localhost

                kaeli said:[color=blue]
                >
                >In article <bo8u6v011ul@dr n.newsguy.com>, REM0VElbspamtra p@cox.net
                >enlightened us with...[color=green]
                >>
                >> Actually, WSH understands Javascript (JScript), too.
                >> Here's an excerpt from one of my HTA's:
                >>[/color]
                >
                >
                >Yeah, but this is running with no server with File-> Open.
                >
                >Can an HTA do that?[/color]

                Yes. I think that it can be done in Javascript in the same
                environments that it can be done with VBScript, but I won't swear.

                [color=blue]
                >I've never tried and I'm a bit of a newbie to HTAs. Too many Unix users
                >here that use Netscape for it to be a valid work project. I just muck
                >around with them a bit on my own computer.
                >
                >Your script looks like it should run with just a browser...does it?[/color]

                I believe it will run in IE, with an appropriate warning about ActiveX.
                I can't test it at the moment.
                [color=blue]
                >A bit OT, but what's the difference between an HTA and a WSH script, if
                >any?[/color]

                The biggest difference is than an HTA runs in a window whose content
                is decribed in HTML, so it's a simple way to create a GUI in a Windows
                environment.

                The example I posted was from an application that presents a list of
                software choices to be installed on the user's desktop. It had to
                be able to run before they have Perl or Tcl installed, and I wanted
                it to be a script. WSH scripts are executed in the background to do
                the actual installs.

                I miss the days when all of my users were on Unix.

                Comment

                • angelbiatch

                  #9
                  Re: Directory listing on localhost

                  On Tue, 04 Nov 2003 13:00:06 -0800, Lee wrote:
                  [color=blue]
                  > I miss the days when all of my users were on Unix.[/color]

                  You mean you miss yer previous job? :D You could get it back ya know...
                  Move to India. ;)

                  Comment

                  • MikeB

                    #10
                    Re: Directory listing on localhost


                    "Lee" <REM0VElbspamtr ap@cox.net> wrote in message news:bo940m01ld o@drn.newsguy.c om...[color=blue]
                    > kaeli said:[color=green]
                    > >
                    > >In article <bo8u6v011ul@dr n.newsguy.com>, REM0VElbspamtra p@cox.net
                    > >enlightened us with...[color=darkred]
                    > >>
                    > >> Actually, WSH understands Javascript (JScript), too.
                    > >> Here's an excerpt from one of my HTA's:
                    > >>[/color]
                    > >
                    > >
                    > >Yeah, but this is running with no server with File-> Open.
                    > >
                    > >Can an HTA do that?[/color]
                    >
                    > Yes. I think that it can be done in Javascript in the same
                    > environments that it can be done with VBScript, but I won't swear.
                    >
                    >[color=green]
                    > >I've never tried and I'm a bit of a newbie to HTAs. Too many Unix users
                    > >here that use Netscape for it to be a valid work project. I just muck
                    > >around with them a bit on my own computer.
                    > >
                    > >Your script looks like it should run with just a browser...does it?[/color]
                    >
                    > I believe it will run in IE, with an appropriate warning about ActiveX.
                    > I can't test it at the moment.
                    >[color=green]
                    > >A bit OT, but what's the difference between an HTA and a WSH script, if
                    > >any?[/color][/color]

                    An HTA does not run in the Security Context of the Browser. When you launch an HTA, the executable
                    that hosts it is MsHTA.exe, which among other things allows client side scripting to interact with
                    the local file system.

                    [color=blue]
                    >
                    > The biggest difference is than an HTA runs in a window whose content
                    > is decribed in HTML, so it's a simple way to create a GUI in a Windows
                    > environment.
                    >
                    > The example I posted was from an application that presents a list of
                    > software choices to be installed on the user's desktop. It had to
                    > be able to run before they have Perl or Tcl installed, and I wanted
                    > it to be a script. WSH scripts are executed in the background to do
                    > the actual installs.
                    >
                    > I miss the days when all of my users were on Unix.
                    >[/color]


                    Comment

                    • kaeli

                      #11
                      Re: Directory listing on localhost

                      In article <GtSdnWPIat-DgjWiRVn-tw@comcast.com> , "MikeB"
                      <m.byerleyATVer izonDottieNetti e> enlightened us with...[color=blue]
                      >
                      > An HTA does not run in the Security Context of the Browser. When you launch an HTA, the executable
                      > that hosts it is MsHTA.exe, which among other things allows client side scripting to interact with
                      > the local file system.
                      >
                      >[/color]

                      But it can still run javascript, or does it really use JScript?

                      And how would a user open an HTA if not via the browser? Double click,
                      like a normal program? Do you have to give a particular extension, like
                      ..hta?

                      Thanks for the info.

                      -------------------------------------------------
                      ~kaeli~
                      Jesus saves, Allah protects, and Cthulhu
                      thinks you'd make a nice sandwich.


                      -------------------------------------------------

                      Comment

                      • MikeB

                        #12
                        Re: Directory listing on localhost

                        Save To SomeFileName.HT A and Double Click to Launch:

                        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
                        <HTML>
                        <HEAD>
                        <TITLE>Mixed Scripting HTA</TITLE>
                        <HTA:APPLICATIO N ID="oHTA"
                        APPLICATIONNAME ="MixedScrip ts"
                        CAPTION="yes"
                        SYSMENU="yes"
                        MAXIMIZEBUTTON= "no"
                        MINIMIZEBUTTON= "no"
                        SHOWINTASKBAR=" no"
                        SINGLEINSTANCE= "yes"
                        SCROLL="NO"
                        BORDER="thin"
                        BORDERSTYLE="di alog"
                        VERSION="1.0"
                        WINDOWSTATE="no rmal"
                        ICON="time.ico" >
                        <SCRIPT LANGUAGE="VBSCR IPT">
                        option Explicit
                        Public Function GetmsgVal(msgIN )
                        Select Case( msgbox( msgIN ,vbYesNo))
                        Case vbYes
                        GetmsgVal="YES"
                        Case vbNo
                        GetmsgVal="NO"
                        case else
                        GetmsgVal="Canc el"
                        end select
                        End Function
                        Public Sub ShowMsg(msgIN)
                        msgbox msgIN
                        End Sub
                        </SCRIPT>
                        <SCRIPT language="javas cript">
                        <!--
                        function JavaScriptClick ()
                        {
                        if (GetMsgVal('Doe s this work for you') == 'YES')
                        ShowMsg('Yep, This Works For Me!');
                        else
                        ShowMsg('Nope, It doesn\'t Work For Me!');
                        }
                        // End -->
                        </SCRIPT>
                        <SCRIPT language="jscri pt">
                        <!--
                        function JScriptClick()
                        {
                        if (GetMsgVal('Doe s this work for you') == 'YES')
                        ShowMsg('Yep, This Works For Me!');
                        else
                        ShowMsg('Nope, It doesn\'t Work For Me!');
                        }
                        // End -->
                        </SCRIPT>
                        </HEAD>
                        <body bgcolor=#BBBBBB >
                        <input type="button" value="JscriptC lick" onClick="JavaSc riptClick()" >
                        <input type="button" value="JavaScri ptClick" onClick="JScrip tClick()" >
                        <br>
                        The Results of either button click come from a VBScript Function called from j/JavaScript
                        </BODY>
                        </HTML>



                        "kaeli" <tiny_one@NOSPA M.comcast.net> wrote in message
                        news:MPG.1a12b9 997e839e2098994 3@nntp.lucent.c om...[color=blue]
                        > In article <GtSdnWPIat-DgjWiRVn-tw@comcast.com> , "MikeB"
                        > <m.byerleyATVer izonDottieNetti e> enlightened us with...[color=green]
                        > >
                        > > An HTA does not run in the Security Context of the Browser. When you launch an HTA, the[/color][/color]
                        executable[color=blue][color=green]
                        > > that hosts it is MsHTA.exe, which among other things allows client side scripting to interact[/color][/color]
                        with[color=blue][color=green]
                        > > the local file system.
                        > >
                        > >[/color]
                        >
                        > But it can still run javascript, or does it really use JScript?
                        >
                        > And how would a user open an HTA if not via the browser? Double click,
                        > like a normal program? Do you have to give a particular extension, like
                        > .hta?
                        >
                        > Thanks for the info.
                        >
                        > -------------------------------------------------
                        > ~kaeli~
                        > Jesus saves, Allah protects, and Cthulhu
                        > thinks you'd make a nice sandwich.
                        > http://www.ipwebdesign.net/wildAtHeart
                        > http://www.ipwebdesign.net/kaelisSpace
                        > -------------------------------------------------[/color]


                        Comment

                        • kaeli

                          #13
                          HTAs: (was Re: Directory listing on localhost)

                          In article <Z_Sdndp0guHotD SiRVn-hA@comcast.com> , "MikeB"
                          <m.byerleyATVer izonDottieNetti e> enlightened us with...[color=blue]
                          > <HTA:APPLICATIO N ID="oHTA"
                          > APPLICATIONNAME ="MixedScrip ts"
                          > CAPTION="yes"
                          > SYSMENU="yes"
                          > MAXIMIZEBUTTON= "no"
                          > MINIMIZEBUTTON= "no"
                          > SHOWINTASKBAR=" no"
                          > SINGLEINSTANCE= "yes"
                          > SCROLL="NO"
                          > BORDER="thin"
                          > BORDERSTYLE="di alog"
                          > VERSION="1.0"
                          > WINDOWSTATE="no rmal"
                          > ICON="time.ico" >[/color]

                          Do you know offhand where I can find a list of these (and other valid)
                          properties and values?
                          I can Google it if you don't have one handy.

                          [color=blue]
                          > <body bgcolor=#BBBBBB >
                          > <input type="button" value="JscriptC lick" onClick="JavaSc riptClick()" >
                          > <input type="button" value="JavaScri ptClick" onClick="JScrip tClick()" >
                          > <br>
                          > The Results of either button click come from a VBScript Function called from j/JavaScript
                          > </BODY>
                          > </HTML>
                          >
                          >[/color]

                          That worked great!
                          Very cool.

                          I think I know what my next free time project is. :)

                          -------------------------------------------------
                          ~kaeli~
                          Jesus saves, Allah protects, and Cthulhu
                          thinks you'd make a nice sandwich.


                          -------------------------------------------------

                          Comment

                          • MikeB

                            #14
                            Re: (was Re: Directory listing on localhost)

                            Gain technical skills through documentation and training, earn certifications and connect with the community


                            "kaeli" <tiny_one@NOSPA M.comcast.net> wrote in message
                            news:MPG.1a12ed 52215899df98994 c@nntp.lucent.c om...[color=blue]
                            > In article <Z_Sdndp0guHotD SiRVn-hA@comcast.com> , "MikeB"
                            > <m.byerleyATVer izonDottieNetti e> enlightened us with...[color=green]
                            > > <HTA:APPLICATIO N ID="oHTA"
                            > > APPLICATIONNAME ="MixedScrip ts"
                            > > CAPTION="yes"
                            > > SYSMENU="yes"
                            > > MAXIMIZEBUTTON= "no"
                            > > MINIMIZEBUTTON= "no"
                            > > SHOWINTASKBAR=" no"
                            > > SINGLEINSTANCE= "yes"
                            > > SCROLL="NO"
                            > > BORDER="thin"
                            > > BORDERSTYLE="di alog"
                            > > VERSION="1.0"
                            > > WINDOWSTATE="no rmal"
                            > > ICON="time.ico" >[/color]
                            >
                            > Do you know offhand where I can find a list of these (and other valid)
                            > properties and values?
                            > I can Google it if you don't have one handy.
                            >
                            >[color=green]
                            > > <body bgcolor=#BBBBBB >
                            > > <input type="button" value="JscriptC lick" onClick="JavaSc riptClick()" >
                            > > <input type="button" value="JavaScri ptClick" onClick="JScrip tClick()" >
                            > > <br>
                            > > The Results of either button click come from a VBScript Function called from j/JavaScript
                            > > </BODY>
                            > > </HTML>
                            > >
                            > >[/color]
                            >
                            > That worked great!
                            > Very cool.
                            >
                            > I think I know what my next free time project is. :)
                            >
                            > -------------------------------------------------
                            > ~kaeli~
                            > Jesus saves, Allah protects, and Cthulhu
                            > thinks you'd make a nice sandwich.
                            > http://www.ipwebdesign.net/wildAtHeart
                            > http://www.ipwebdesign.net/kaelisSpace
                            > -------------------------------------------------[/color]


                            Comment

                            • MikeB

                              #15
                              Re: Directory listing on localhost

                              The security context in an HTA allows me to start an HTA with Frames, open a remote url in Frame2
                              and feed database info into Frame1 to AutoFill an online Form in Frame2 (of course, when this is a
                              repetitious task and the data entry would be otherwise duplicated)...


                              "MikeB" <m.byerleyATVer izonDottieNetti e> wrote in message news:Z_Sdndp0gu HotDSiRVn-hA@comcast.com. ..[color=blue]
                              > Save To SomeFileName.HT A and Double Click to Launch:
                              >
                              > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
                              > <HTML>
                              > <HEAD>
                              > <TITLE>Mixed Scripting HTA</TITLE>
                              > <HTA:APPLICATIO N ID="oHTA"
                              > APPLICATIONNAME ="MixedScrip ts"
                              > CAPTION="yes"
                              > SYSMENU="yes"
                              > MAXIMIZEBUTTON= "no"
                              > MINIMIZEBUTTON= "no"
                              > SHOWINTASKBAR=" no"
                              > SINGLEINSTANCE= "yes"
                              > SCROLL="NO"
                              > BORDER="thin"
                              > BORDERSTYLE="di alog"
                              > VERSION="1.0"
                              > WINDOWSTATE="no rmal"
                              > ICON="time.ico" >
                              > <SCRIPT LANGUAGE="VBSCR IPT">
                              > option Explicit
                              > Public Function GetmsgVal(msgIN )
                              > Select Case( msgbox( msgIN ,vbYesNo))
                              > Case vbYes
                              > GetmsgVal="YES"
                              > Case vbNo
                              > GetmsgVal="NO"
                              > case else
                              > GetmsgVal="Canc el"
                              > end select
                              > End Function
                              > Public Sub ShowMsg(msgIN)
                              > msgbox msgIN
                              > End Sub
                              > </SCRIPT>
                              > <SCRIPT language="javas cript">
                              > <!--
                              > function JavaScriptClick ()
                              > {
                              > if (GetMsgVal('Doe s this work for you') == 'YES')
                              > ShowMsg('Yep, This Works For Me!');
                              > else
                              > ShowMsg('Nope, It doesn\'t Work For Me!');
                              > }
                              > // End -->
                              > </SCRIPT>
                              > <SCRIPT language="jscri pt">
                              > <!--
                              > function JScriptClick()
                              > {
                              > if (GetMsgVal('Doe s this work for you') == 'YES')
                              > ShowMsg('Yep, This Works For Me!');
                              > else
                              > ShowMsg('Nope, It doesn\'t Work For Me!');
                              > }
                              > // End -->
                              > </SCRIPT>
                              > </HEAD>
                              > <body bgcolor=#BBBBBB >
                              > <input type="button" value="JscriptC lick" onClick="JavaSc riptClick()" >
                              > <input type="button" value="JavaScri ptClick" onClick="JScrip tClick()" >
                              > <br>
                              > The Results of either button click come from a VBScript Function called from j/JavaScript
                              > </BODY>
                              > </HTML>
                              >
                              >
                              >
                              > "kaeli" <tiny_one@NOSPA M.comcast.net> wrote in message
                              > news:MPG.1a12b9 997e839e2098994 3@nntp.lucent.c om...[color=green]
                              > > In article <GtSdnWPIat-DgjWiRVn-tw@comcast.com> , "MikeB"
                              > > <m.byerleyATVer izonDottieNetti e> enlightened us with...[color=darkred]
                              > > >
                              > > > An HTA does not run in the Security Context of the Browser. When you launch an HTA, the[/color][/color]
                              > executable[color=green][color=darkred]
                              > > > that hosts it is MsHTA.exe, which among other things allows client side scripting to interact[/color][/color]
                              > with[color=green][color=darkred]
                              > > > the local file system.
                              > > >
                              > > >[/color]
                              > >
                              > > But it can still run javascript, or does it really use JScript?
                              > >
                              > > And how would a user open an HTA if not via the browser? Double click,
                              > > like a normal program? Do you have to give a particular extension, like
                              > > .hta?
                              > >
                              > > Thanks for the info.
                              > >
                              > > -------------------------------------------------
                              > > ~kaeli~
                              > > Jesus saves, Allah protects, and Cthulhu
                              > > thinks you'd make a nice sandwich.
                              > > http://www.ipwebdesign.net/wildAtHeart
                              > > http://www.ipwebdesign.net/kaelisSpace
                              > > -------------------------------------------------[/color]
                              >
                              >[/color]


                              Comment

                              Working...