Jump to content

[SOLVED] help generating specific directories..


hotwire

Recommended Posts

Hello forum and moderators,

 

I am having a problem generating a predefined directory that will check if the directory exists and if so just add a number and keep checking if exist.

 

For example, the predefined directory is named 'memalb', and I want each new directory to be named, 'memalb1' memalb2, memalb3 etc..

 

The coding I am currently using makes each new directory, memalb1, memalb12, memalb123,  etc..

 

here is my current coding:

$y=0;
$xdir="memalb";
$ckd= file_exists($xdir);
if ($ckd==1){
while ($ckd==1){
$xdir=$xdir.$y;
$ckd=file_exists($xdir);
++$y;
}
}
        mkdir($xdir);

 

Thanks for any help on this..

Like this?

 

$dir = "memalb";
$check = file_exists($dir);
$i = 0;

while($check){
$i++;
$check = file_exists($dir.$i);
}

if($i == 0){
//Original folder does not exist! Create it.
}else{
$folder = $dir.$i;
echo $folder;
}

Hi ProjectFear,

 

Thanks for the coding, It had 1 minor error I fixed which was the "if (i == 0)"  should be "if ($check == 0)"..  However it does work..  Thanks Alot for your help, it is much appreciated..  Thank You! 

 

hotwire

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.