469,280 Members | 1,811 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,280 developers. It's quick & easy.

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.

Jul 20 '05 #1
16 24762
In article <bo**********@prometheus.acsu.buffalo.edu>, rg27
@cse.buffalo.edu enlightened us with...
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.

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.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Jul 20 '05 #2
kaeli wrote:
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?


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.

Jul 20 '05 #3
Try Perl
Jul 20 '05 #4
In article <bo**********@prometheus.acsu.buffalo.edu>, rg27
@cse.buffalo.edu enlightened us with...

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.


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="vbscript">
'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\wwwroot"

Set fs2 = CreateObject("Scripting.FileSystemObject")
Set f2 = fs2.GetFolder(folderspec2)

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.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Jul 20 '05 #5
Lee
kaeli said:

In article <bo**********@prometheus.acsu.buffalo.edu>, rg27
@cse.buffalo.edu enlightened us with...

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.


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


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.FileSystemObject");

function getScriptList(folderspec){
var f = fso.GetFolder(folderspec);
var fc = new Enumerator(f.files);
for (; !fc.atEnd(); fc.moveNext()){
var fileName=fc.item().Name
if(-1!=fileName.search(/^Install/)){
// do stuff with filename beginning with "Install"
}
}
}

Jul 20 '05 #6
In article <bo*********@drn.newsguy.com>, RE**************@cox.net
enlightened us with...

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

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.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Jul 20 '05 #7
Lee
kaeli said:

In article <bo*********@drn.newsguy.com>, RE**************@cox.net
enlightened us with...

Actually, WSH understands Javascript (JScript), too.
Here's an excerpt from one of my HTA's:
Yeah, but this is running with no server with File-> Open.

Can an HTA do that?


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.

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?
I believe it will run in IE, with an appropriate warning about ActiveX.
I can't test it at the moment.
A bit OT, but what's the difference between an HTA and a WSH script, if
any?


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.

Jul 20 '05 #8
On Tue, 04 Nov 2003 13:00:06 -0800, Lee wrote:
I miss the days when all of my users were on Unix.


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

Jul 20 '05 #9

"Lee" <RE**************@cox.net> wrote in message news:bo*********@drn.newsguy.com...
kaeli said:

In article <bo*********@drn.newsguy.com>, RE**************@cox.net
enlightened us with...

Actually, WSH understands Javascript (JScript), too.
Here's an excerpt from one of my HTA's:
Yeah, but this is running with no server with File-> Open.

Can an HTA do that?


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.

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?


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


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.


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.

Jul 20 '05 #10
In article <Gt********************@comcast.com>, "MikeB"
<m.byerleyATVerizonDottieNettie> enlightened us with...

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.


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
-------------------------------------------------
Jul 20 '05 #11
Save To SomeFileName.HTA and Double Click to Launch:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>Mixed Scripting HTA</TITLE>
<HTA:APPLICATION ID="oHTA"
APPLICATIONNAME="MixedScripts"
CAPTION="yes"
SYSMENU="yes"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
SHOWINTASKBAR="no"
SINGLEINSTANCE="yes"
SCROLL="NO"
BORDER="thin"
BORDERSTYLE="dialog"
VERSION="1.0"
WINDOWSTATE="normal"
ICON="time.ico">
<SCRIPT LANGUAGE="VBSCRIPT">
option Explicit
Public Function GetmsgVal(msgIN)
Select Case( msgbox( msgIN ,vbYesNo))
Case vbYes
GetmsgVal="YES"
Case vbNo
GetmsgVal="NO"
case else
GetmsgVal="Cancel"
end select
End Function
Public Sub ShowMsg(msgIN)
msgbox msgIN
End Sub
</SCRIPT>
<SCRIPT language="javascript">
<!--
function JavaScriptClick()
{
if (GetMsgVal('Does this work for you') == 'YES')
ShowMsg('Yep, This Works For Me!');
else
ShowMsg('Nope, It doesn\'t Work For Me!');
}
// End -->
</SCRIPT>
<SCRIPT language="jscript">
<!--
function JScriptClick()
{
if (GetMsgVal('Does 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="JscriptClick" onClick="JavaScriptClick()" >
<input type="button" value="JavaScriptClick" onClick="JScriptClick()" >
<br>
The Results of either button click come from a VBScript Function called from j/JavaScript
</BODY>
</HTML>

"kaeli" <ti******@NOSPAM.comcast.net> wrote in message
news:MP************************@nntp.lucent.com...
In article <Gt********************@comcast.com>, "MikeB"
<m.byerleyATVerizonDottieNettie> enlightened us with...

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.


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

Jul 20 '05 #12
In article <Z_********************@comcast.com>, "MikeB"
<m.byerleyATVerizonDottieNettie> enlightened us with...
<HTA:APPLICATION ID="oHTA"
APPLICATIONNAME="MixedScripts"
CAPTION="yes"
SYSMENU="yes"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
SHOWINTASKBAR="no"
SINGLEINSTANCE="yes"
SCROLL="NO"
BORDER="thin"
BORDERSTYLE="dialog"
VERSION="1.0"
WINDOWSTATE="normal"
ICON="time.ico">
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.

<body bgcolor=#BBBBBB>
<input type="button" value="JscriptClick" onClick="JavaScriptClick()" >
<input type="button" value="JavaScriptClick" onClick="JScriptClick()" >
<br>
The Results of either button click come from a VBScript Function called from j/JavaScript
</BODY>
</HTML>


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
-------------------------------------------------
Jul 20 '05 #13
http://msdn.microsoft.com/workshop/a...asp?frame=true

"kaeli" <ti******@NOSPAM.comcast.net> wrote in message
news:MP************************@nntp.lucent.com...
In article <Z_********************@comcast.com>, "MikeB"
<m.byerleyATVerizonDottieNettie> enlightened us with...
<HTA:APPLICATION ID="oHTA"
APPLICATIONNAME="MixedScripts"
CAPTION="yes"
SYSMENU="yes"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
SHOWINTASKBAR="no"
SINGLEINSTANCE="yes"
SCROLL="NO"
BORDER="thin"
BORDERSTYLE="dialog"
VERSION="1.0"
WINDOWSTATE="normal"
ICON="time.ico">


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.

<body bgcolor=#BBBBBB>
<input type="button" value="JscriptClick" onClick="JavaScriptClick()" >
<input type="button" value="JavaScriptClick" onClick="JScriptClick()" >
<br>
The Results of either button click come from a VBScript Function called from j/JavaScript
</BODY>
</HTML>


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

Jul 20 '05 #14
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.byerleyATVerizonDottieNettie> wrote in message news:Z_********************@comcast.com...
Save To SomeFileName.HTA and Double Click to Launch:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>Mixed Scripting HTA</TITLE>
<HTA:APPLICATION ID="oHTA"
APPLICATIONNAME="MixedScripts"
CAPTION="yes"
SYSMENU="yes"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
SHOWINTASKBAR="no"
SINGLEINSTANCE="yes"
SCROLL="NO"
BORDER="thin"
BORDERSTYLE="dialog"
VERSION="1.0"
WINDOWSTATE="normal"
ICON="time.ico">
<SCRIPT LANGUAGE="VBSCRIPT">
option Explicit
Public Function GetmsgVal(msgIN)
Select Case( msgbox( msgIN ,vbYesNo))
Case vbYes
GetmsgVal="YES"
Case vbNo
GetmsgVal="NO"
case else
GetmsgVal="Cancel"
end select
End Function
Public Sub ShowMsg(msgIN)
msgbox msgIN
End Sub
</SCRIPT>
<SCRIPT language="javascript">
<!--
function JavaScriptClick()
{
if (GetMsgVal('Does this work for you') == 'YES')
ShowMsg('Yep, This Works For Me!');
else
ShowMsg('Nope, It doesn\'t Work For Me!');
}
// End -->
</SCRIPT>
<SCRIPT language="jscript">
<!--
function JScriptClick()
{
if (GetMsgVal('Does 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="JscriptClick" onClick="JavaScriptClick()" >
<input type="button" value="JavaScriptClick" onClick="JScriptClick()" >
<br>
The Results of either button click come from a VBScript Function called from j/JavaScript
</BODY>
</HTML>

"kaeli" <ti******@NOSPAM.comcast.net> wrote in message
news:MP************************@nntp.lucent.com...
In article <Gt********************@comcast.com>, "MikeB"
<m.byerleyATVerizonDottieNettie> enlightened us with...

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.


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


Jul 20 '05 #15
In article <eu********************@comcast.com>, "MikeB"
<m.byerleyATVerizonDottieNettie> enlightened us with...
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)...


Okay, now I'm jealous.

I just got a call from a recruiter about a job that uses the .NET
framework, so I need to brush up on my Windows knowledge, anyway. *G*
My stuff is all on a unix platform right now.

*crossing fingers*

-------------------------------------------------
~kaeli~
Jesus saves, Allah protects, and Cthulhu
thinks you'd make a nice sandwich.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Jul 20 '05 #16
In article <I-********************@comcast.com>, "MikeB"
<m.byerleyATVerizonDottieNettie> enlightened us with...
http://msdn.microsoft.com/workshop/a...asp?frame=true


Cool, thanks!

-------------------------------------------------
~kaeli~
Jesus saves, Allah protects, and Cthulhu
thinks you'd make a nice sandwich.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Jul 20 '05 #17

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by xEM | last post: by
19 posts views Thread by SU News Server | last post: by
2 posts views Thread by Tom | last post: by
16 posts views Thread by B Letts | last post: by
8 posts views Thread by gil | last post: by
6 posts views Thread by David | last post: by
4 posts views Thread by techusky | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.