Dear my friends...

I want my code does an action if it find a directory or file, namely: storing 
the url/path of a file or a directory onto mysql database.

I am meaning, my code should look up every file/directory name resides under 
the "$rootdir" iteratively for doing storing onto mysql on each find.

The algorithm For doing find from beginning to the end of the 1 level under 
$rootdir is still simple, it's only a "while{..}{...}". 
But the problem comes when the directory has a/some directory/-es whereas my 
code should also find them and stores them onto the mysql. 
If every directory has a limited level (for instance maximum only 3 level 
subdirectories below to the bottom) then all I have to do is simply creating 
nested "while(...)[..] " for 3 level. But in this case of course each directory 
may unpredictably has hundreds or thousands subdirectories/files in hundreds or 
thousands levels below to the bottom.

Please suggest me some ideas where I can implement into my codes in order to 
enable my code to find all subdirectories and files where placed under $rootdir.
A very simple code-sample is very......very.......welcomed.

Here is my current code under below. This code still only can find 1 level, 
only exactly 1 level under $rootdir.
---------------------
package iterdir;
use kueri;

sub baru{
  my $kelas = shift if @_;
  print "Nama superkelas: $kelas \n";
  return( bless{} );
}

sub bukadir{
  my $kelas = shift;
  $rootdir="/home/patrikh/sementara/tes";
  opendir("dirku", "$rootdir");
  $statusp=chdir($rootdir);
  if ($statusp){
    print "berhasil membuka direktori-->$rootdir\n";
    while ($entridir=readdir("dirku")){
      print "entridir: $entridir\n";
      $sqlku=kueri->baru;
      $sqlku->konek;
      if (($entridir ne '.') and ($entridir ne '..')){
        my $strsql = "insert into tblarsip (location) values ('".$entridir."')";
        print "strsql: $strsql\n";
        $sth=$kueri::dbh->prepare($strsql);
        $sth->execute;
        $sth->finish;
      }
    }
  } else{
    print "gagal membuka direktori yang diinginkan: $rootdir\n";
    exit 1;
  }
}

1;

-- 
Patrik Hasibuan <[EMAIL PROTECTED]>
Junior Programmer

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


  • Need idea for doing au... Patrik Hasibuan

Reply via email to