Jump to content

Remote Directory Name Pattern


bschultz

Recommended Posts

I work at a radio station.  Each week, we have to download (using SCP or wget) a bunch of mp3's to air during the weekend.  The problem I'm having is that the remote directory that these files are located in changes the name from one week to another.

 

For instance, this week one directory is named 'Live In Concert ROCK (Sunday) 02.22.15 version3'.  Next week, it might be 'Live In Concert ROCK (Sunday) 02.29.15 version2'

 

What I need is a matching pattern of 'Live in Concert' and the 'date'...and there will be other stuff in between those two patterns.  To complicate this...it's on a remote machine.

 

What are my options?

 

Thanks.

Link to comment
Share on other sites

What are you trying to accomplish by creating a pattern? Are you trying to dynamically determine which folder to download files from? If so, you can (pretty sure) download the folder list and compare the names to do that. I've not used FTP functions in PHP enough to know. But, in determining the pattern, I assume you want to look for a specific data based on the current day's date. It appears you want to always use a Sunday date. So, how do want to choose "which" Sunday to use? I assume if it is Monday to Saturday, you want to use the next Sunday. But, what if you run the code on a Sunday? Should it use the current date or the next week's Sunday?

Link to comment
Share on other sites

If you have permission the other server add a script to find the latest folder by date.

If not ask them to do it.

 

something like this

<?php
function latestDirectory($path = NULL)
{
    if ($path == NULL) {
        $path = "/";
    }
    $list = array();
    $path = rtrim($path, "/");
    if (substr($path, 0, 1) != "/") {
        $path = "/" . $path;
    }
    if ($path == "/") {
        $path = $_SERVER['DOCUMENT_ROOT'];
    } else {
        $path = $_SERVER['DOCUMENT_ROOT'] . $path;
    }
    $working_dir = getcwd();
    chdir($path);
    $ret_val = false;
    if ($p = opendir($path)) {
        while (false !== ($file = readdir($p))) {
            if ($file{0} != '.' && is_dir($file)) {
                $timestamp   = filemtime($path . '/' . $file);
                $pretty_date = date("m/d/Y h:i:s A", $timestamp);
                $list[]      = array(
                    "directory" => $path . '/' . $file,
                    "date" => $pretty_date,
                    "timestamp" => $timestamp
                );
            }
        }
        rsort($list);
    }
    chdir($working_dir);
    //return list array;
    return $list;
}


$list_array = latestDirectory(); //use directory names,document root included in function
if (!empty($list_array)) {
    //last directory created
    echo $list_array['0']['directory'];
   
    //list of directories
    echo "<pre>";
    print_r($list_array);
    echo "<pre>";
}
?>
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.