473,322 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 24950
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: xEM | last post by:
I have in Apache2 (win32) aliased directory, for example: Alias /ftp/mp3/ "D:/mp3/" <Directory "D:/mp3"> .... </Directory> Address to this directory will be: http://localhost/ftp/mp3/ How...
19
by: SU News Server | last post by:
I've struggled with this for quite a while and I'm am just not sure what is going on. I have the following code import os def buildList( directory='/Users/mkonrad' ) dirs = listing =...
2
by: Tom | last post by:
I need to get a directory listing through http. If I put the directory path in the browser address bar such as http://somewebpage.com/subdir I get the listing of the directory. Of course this is...
16
by: B Letts | last post by:
Hi - I'm currently using the FileUpload control to allow people to upload files to my website. This all works fine, as long as I'm going to a physical path on my server. However, I need to...
8
by: gil | last post by:
Is it possible to prevent a browser from listing the entire contents of a folder? The site, is hosted on my ISP with the following layout- site/ "user name from ISP" pagefile (dir)...
6
by: David | last post by:
Hi all, Using C# .NET 1.1 I am creating a CMS type of application. So far so good. I have a templating system in place that works fantastically. I can remap non-real files and folders and get...
7
by: epikto | last post by:
I have a mapped share that I am trying to get a listing of all the files that it contains. I use the following code to access the contents String files = Directory.GetFiles(path); I can then...
4
by: techusky | last post by:
I have a *very* simple script written that displays the directory listing of the current working directory, but I am having some difficulty when I try to change folders. Basically, I have my $dir...
1
by: Steve | last post by:
My site is hosted on a Godaddy reseller site. Godaddy only allows the use of Curl to access remote sites. What is the method for listing a directory after connecting to the site with Curl? ...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.