satre Posted January 19, 2011 Share Posted January 19, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/224953-find-a-directory-in-expanded-file-and-copy-its-contents/ Share on other sites More sharing options...
trq Posted January 19, 2011 Share Posted January 19, 2011 You'll need to recurse through the directory structure until you find what your after. Not too difficult. Quote Link to comment https://forums.phpfreaks.com/topic/224953-find-a-directory-in-expanded-file-and-copy-its-contents/#findComment-1161857 Share on other sites More sharing options...
satre Posted January 19, 2011 Author Share Posted January 19, 2011 Thanks, that's great, however, which command will get the path without me knowing it ahead of time? So sorry, I'm a bit rusty after a long hiatus. Quote Link to comment https://forums.phpfreaks.com/topic/224953-find-a-directory-in-expanded-file-and-copy-its-contents/#findComment-1161862 Share on other sites More sharing options...
trq Posted January 19, 2011 Share Posted January 19, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/224953-find-a-directory-in-expanded-file-and-copy-its-contents/#findComment-1161867 Share on other sites More sharing options...
trq Posted January 19, 2011 Share Posted January 19, 2011 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"); } } } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/224953-find-a-directory-in-expanded-file-and-copy-its-contents/#findComment-1161868 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.