Jump to content

[SOLVED] Get a file name from a path


d22552000

Recommended Posts

Yes, this is almost like PARSE_URL, but no this is not what I want to do.

 

Simplest way to explain it is by example.

 

I want to turn this:

./`admin/plugins/top/*.php

Into this:

*

 

I want to get the name of the script IN the file.  The files PATH, is not going to be /`admin/plugins/top/.

The paths will be ./`admin/plugins/*  (top | middle | bottom).

 

How would I convert these names?

Link to comment
Share on other sites

nope, I am doing this:

 

Scanning a directory for files using glob

creating a header (h#) for them using their NAME

eval'ing these files to add them to this script im in.

 

ending that header block (/h#)

 

 

currently im doing this a very long way:

 

<?PHP

function parse_plugin($con,$file) {
    $file = str_replace('./`admin/plugins/','',$file);
    $file = str_replace('bottom','',$file);
    $file = str_replace('middle','',$file);
    $file = str_replace('top','',$file);
    $file = str_replace('.php','',$file);
    $file = str_replace('/','',$file);

    begin_frame($file,true);
     eval($con);
    end_frame();
}

foreach(glob('./`admin/plugins/top/*.php') as $file) {
  parse_plugin(file_get_contents($file),$file);
}

//--bunch of script--//

foreach(glob('./`admin/plugins/middle/*.php') as $file) {
  parse_plugin(file_get_contents($file),$file);
}

//--bunch of script--//

foreach(glob('./`admin/plugins/bottom/*.php') as $file) {
  parse_plugin(file_get_contents($file),$file);
}

?>

Link to comment
Share on other sites

You really need to explain your question alot clearer. Given a filepath, basename returns the file name. eg;

 

#!/usr/bin/php
<?php

    foreach (glob('~/scratch/*.php') as $filepath) {
        echo "$filepath : " . basename($filepath) . "\n";
    }  

?>

 

returns....

 

/home/thorpe/scratch/abs.php : abs.php
/home/thorpe/scratch/ch.php : ch.php
/home/thorpe/scratch/filter.php : filter.php

 

on my machine.

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.