Log in

View Full Version : Resolved [mkdir] exists or not



sysout
02-15-2009, 11:51 PM
How to check if a directory if exists or not?


if($induk[$i] != 'root'){
try{
mkdir("../../stok/".$induk[$i], 777);
mkdir("../../thumbs/".$induk[$i], 777);
}
catch(Exception $e){
//nothing to do
}
mkdir("../../stok/".$induk[$i]."/".$kategori[$i], 777);
mkdir("../../thumbs/".$induk[$i]."/".$kategori[$i], 777);
}
else{
mkdir("../../stok/".$kategori[$i], 777);
mkdir("../../thumbs/".$kategori[$i], 777);
}
I've tried to use try catch Exception, but there's no effect at all.

Hope that somebody can help me.
Thanks

Nile
02-15-2009, 11:53 PM
<?php
$file = "some_file.txt";
if(file_exists($file)){
echo "The file ".$file." exists!";
}
else {
echo "Sorry, the file ".$file." doesn't exist!";
}
?>

sysout
02-15-2009, 11:55 PM
can it effects directory?

Thanks

Nile
02-15-2009, 11:56 PM
What do you mean 'effect'?

sysout
02-16-2009, 12:16 AM
file_exists($file) -> can it be done for :

$folder = "../../stok/Temp";

file_exists($folder);

is it works?

Nile
02-16-2009, 12:22 AM
File_exists returns 1 or 0. So no... You'd have to do:


<?php
// ... code here
echo file_exists($folder);
?>

Which will echo 1 if it exists, and nothing if it doesn't.

sysout
02-16-2009, 12:44 AM
great...it works...thanks a lot palz..

You're really expert, excellent

Nile
02-16-2009, 12:47 AM
I'm glad to help you sysout! Your welcome!

It seems your topic is solved... Please set the status to resolved.. To do this:
Go to your first post ->
Edit your first post ->
Click "Go Advanced" ->
Then in the drop down next to the title, select "RESOLVED"

sysout
02-16-2009, 01:22 AM
yeap..absolutely done..

Thanks a lot palz, hope that I can help you too

Twey
02-16-2009, 01:30 AM
File_exists returns 1 or 0.Actually, true or false. In PHP these are hacked up with 1 and the empty string, ''. Why? Why are the two equivalents taken from different types? Why do people still use PHP? Nobody knows.

Nile
02-16-2009, 01:32 AM
There's nothing wrong with php...

What else are we gonna use anyways? ASP? Yuck..

Twey
02-16-2009, 01:47 AM
Of course not. *cough (http://b.lericson.se/~toxik/php_sucks_rant.log)* *cough (http://www.bitstorm.org/edwin/en/php/)*

Alternatives? Python, Ruby, Haskell, Common Lisp, C#, F#... heck, even Java's somewhat preferable. It may be huge and clumsy, but it doesn't have hacks like that in it.