Jump to content


Photo

Check if file existes


  • Please log in to reply
9 replies to this topic

#1 dandandan

dandandan
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 05 October 2006 - 04:38 AM

whats a function/way that i can check if a file exists? eg:

$number="1";
$filename="test";

untill (A FILE NAMED $filename$number.txt DOES NOT EXIST) {
$number++
}


Thats main idea of what i want to use it for, i just dont know what function to use.

#2 Hi I Am Timbo

Hi I Am Timbo
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 05 October 2006 - 04:42 AM

I would try the file_exists() function

#3 Hi I Am Timbo

Hi I Am Timbo
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 05 October 2006 - 04:43 AM

<?php
$number="1";
$filename="test";

while(file_exists($filename$number.txt))
{
    $number++;
}
?>


#4 markbett

markbett
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 05 October 2006 - 04:46 AM

though you would want to add some code in there to do something to the file because the example will add indefinately.....

#5 Hi I Am Timbo

Hi I Am Timbo
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 05 October 2006 - 04:47 AM

I don't think it will.  It will not do anything, but it will not be an infinite loop.  It will add until the file doesn't exist, doing nothing each time. 

#6 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 05 October 2006 - 04:53 AM

slight modification to your code Timbo:

<?php
$number="1";
$filename="test";

while(!file_exists($filename.$number.'.txt'))
{
    $number++;
}
?>

you forgot the ! in the condition, and a . between your $filename and $number, and also forgot some quotes for the .txt
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#7 Hi I Am Timbo

Hi I Am Timbo
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 05 October 2006 - 05:16 AM

yes, thank you.

#8 Hi I Am Timbo

Hi I Am Timbo
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 05 October 2006 - 05:17 AM

Actually, the ! shouldn't be there.  I think they wanted to do something to all files until they don't exist anymore.  But I did forget the .

#9 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 05 October 2006 - 05:26 AM

okay yes you are right about the !
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#10 dandandan

dandandan
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 05 October 2006 - 05:45 AM

thanks guys, twas a great help. Its up and working now




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users