Dear Monks,

The folowing script I got.
When it's browse local dir's output is ok.
If it's browsing local shared dir's output is ok.

If it's browsing remote shared dir's we get following error : Can't chdir to //NLHUB515025T/sh_robert No such file or directory.
Is there an other way to read files and dirs on a remote drive?
#!perl -w use strict; use CGI; use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); my $cgi = new CGI(); my $url = "/cgi-bin/index/index-tp.pl"; my $docroot = "//NLHUB515025T/sh_robert/"; my $docdir = $cgi->param("Dir") || ""; print $cgi->header(); my $newStyle=<<END; <!-- body { font-size: 10pt; font-family: sans-serif; } --> END print $cgi->start_html(-title=>'Browse directory', -style=>{-code=>$newStyle} ); if (-d "$docroot$docdir") { chdir("$docroot$docdir") or die "Can't chdir to $docroot$docdir\n" +; opendir(DIR, "$docroot$docdir") or die "Can't open directory $docr +oot$docdir\n"; my @entries = grep({! /^\.{1,2}\z/} readdir(DIR)); closedir(DIR); my @dirs = grep({ -d } @entries); my @files = grep({ -f } @entries); my $dircount = $#dirs + 1; my $filecount = $#files + 1; my $dirhtml = ""; foreach (sort(@dirs)) { $dirhtml .= "[" . $cgi->a({href => "$url?Dir=$docdir/$_"}, $_) + . "] "; } if ($dircount > 0) { print $cgi->p($cgi->strong("Subdirectories of $docdir"), $cgi- +>br(), $cgi->span({style => "background-color : #dddddd"}, $dirhtml)) +; } if ($filecount > 0) { print $cgi->start_table({border => 0, cellspacing => 0, cellpa +dding => 0}); print $cgi->start_table({border => 0, cellspacing => 0, cellpa +dding => 0}); print $cgi->Tr($cgi->th({align => "left"}, [("Filename", "&nbs +p;Size", "&nbsp;Date", "Time")])); foreach (sort(@files)) { my $size = (stat($_))[7]; my $mtime = (stat(_))[9]; my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $ +isdst) = localtime($mtime); my $date = sprintf("&nbsp;%04d-%02d-%02d&nbsp;", $year + 1 +900, $mon + 1, $mday); my $time = sprintf("%02d:%02d", $hour, $min); print $cgi->Tr($cgi->td($cgi->a({href => "$docdir/$_"}, "$ +_&nbsp;")), $cgi->td({align => "right"}, $size), $cgi->td([$date, $ti +me])); } print $cgi->end_table(); } print $cgi->p($cgi->em("Directories:&nbsp;", $dircount, "&nbsp;-&n +bsp;Files:&nbsp;", $filecount)); } print $cgi->end_html();




Thank you in advance,

perlboer

In reply to remote directory browsing give no listing by perlboer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.