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
https://forums.phpfreaks.com/topic/141739-solved-get-directories-from-range/
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)
?>

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

Archived

This topic is now archived and is closed to further replies.

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