Jump to content

[SOLVED] get directories from range


HektoR

Recommended Posts

hi all :)

 

so, i'm making script whic must get directories from range.

i have main directory "MAIN";

in MAIN directory there are few dir"

"01" , "02" , "03" , "03" , "04".

and i want to, when i indicate range, for example: from "02" to "04"

script must show me all directories in this range ...

 

thats all.

 

 

thank you :)

Link to comment
Share on other sites

So if for example,

 

if you have folder

1

2

5

6

9

10

11

 

and done dirrange(2,10)

you want it to return

2

5

6

9

10

 

right ?

 

if so you could try something like this

<?php
$R = range(2,10);
$folder = array();
$Path = "path/to/folders/";
foreach ($R as $V)
{
if(is_dir($Path.$V)) $folder[] = $V;
}
echo "<pre>";
print_r($folder)
?>

Link to comment
Share on other sites

sprintf

EG

<?php
$R = range(2,10);
$folder = array();
foreach ($R as $V)
{
$V= sprintf("%02s",$V); //add the 0 for the 1to9
if(is_dir($V))
{
	$folder[] = $V;
	echo "FOUND: $V<br>";
}else{
	echo "NOT FOUND: $V<br>";
}
}
echo "<pre>";
print_r($folder)

?>

 

EDIT: missed a / on the comment

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.