Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get_files problem

Status
Not open for further replies.

Rowina

Technical User
Aug 5, 2002
4
0
0
HK
Hi Everyone,

Maybe you've read my last thread about the basedir problem, fortunatelly I'm able to fix that. But now I realize that another problem has pop up. When I use this script on my Window NT server, it seems doesn't recognize some of the commands in the code, under the 'sub get_files' method. It doesn't read the 'pwd' and 'ls'. Below is a fragment of Matt's simple search scripts. By the way, this problem works perfectly on my own website(on the Internet).
Does this mean that the code is only suitable for UNIX but not Window NT? If so, what adjustment do I have to make in order to make this piece of script works on Window NT server? Thank you very much!!

best regards,

Rowina

sub get_files
{
chdir($basedir);
foreach $file (@files)
{
$ls = `ls $file`;
@ls = split(/\s+/,$ls);
foreach $temp_file (@ls)
{
if (-d $file)
{
$filename = "$file$temp_file";
if (-T $filename)
{
push(@FILES,$filename);
}
}
elsif (-T $temp_file)
{
push(@FILES,$temp_file);
}
}
}
}
 
[tt]chdir[/tt] is used in Unix Bourne and C Shell AND NT so you are okay with it here.
[tt]ls [/tt]is used in Unix shells but NOT NT so you should use [tt]dir[/tt] instead for your script.
[tt]pwd[/tt] is used for Unix and [tt]cd[/tt] should be used for NT current working directory.

Example:
$ls = `ls $file`; #unix

$ls = `dir $file`; #NT =================
Bad Company Music
=================
 
You'll tend to run into this sort of problem a lot if you use commands in backticks on scripts that need to run in both a unix and microsoft environment.

For this particular case, you might try using the perl opendir/readdir/closedir commands to build your array of filenames.

Richard
 
Thank you very much guys!!

Rowina
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top