Jump to content

Find a directory in expanded file and copy its contents


satre

Recommended Posts

Seems this should be easy, but I'm not finding the solution. Functions like scandir, readdir, and glob that I've been looking at all seem to need me to actually know more about my directory path than I can ahead of time.

 

Here's what I want to do:

1. expand a .tar file (consists of directory, subdirectories, files, and is variable) that I've uploaded to the server

2. look through that expanded directory for a subdirectory named ".pn" -- (note that all my .tar files will have this folder deep in several subdirectories that will be variable in number and have different names depending on the original .tar file)

3. copy the entire contents of the .pn folder to another folder already on my server

 

The hosting company, no doubt, has likely blocked some of the functions I'll need as well, but if someone can point me in the right direction to start, it would be greatly appreciated.

 

Thanks!

Satre

Here, something like (not tested).....

 

<?php

function getPN($path) {
  if ($dh = opendir($path)) {
    while(false !== ($file = readdir($dh))) {
      if (is_dir("$path/$file")) {
        if (substr($file, -3) == '.pn') {
          return "$path/$file";
        } else {
          getPN("$path/$file");
        }
      }
    }
  }
}
?> 

 

that should return the path to your *.pn directory.

You may as well go all out and get the contents I suppose

 

<?php

function getPNContents($path) {
  if ($dh = opendir($path)) {
    while(false !== ($file = readdir($dh))) {
      if (is_dir("$path/$file")) {
        if (substr($file, -3) == '.pn') {
          return scandir("$path/$file");
        } else {
          getPNContents("$path/$file");
        }
      }
    }
  }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.