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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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");
        }
      }
    }
  }
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.