Re: touch()ing it....advise needed.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On May 13, 2006, at 7:48 AM, Ryan A wrote:

Hey,
Heres my setup, I have a directory full of files and I
get a request with an array of filenames
For this example:
a.txt
b.txt
c.txt

if the above files dont already exist I need to create
them (I am using touch() instead of fopen())

My question is which would you recommend, doing a
readdir() and getting all the existing filenames in an
array then doing a loop to see which exists and create
the others OR

just taking the new filenames, doing a while/for loop
with a files_exists() on each and then creating the
files....

I am favouring the second approach as in the first
approach there are a lot of files the array could be
pretty big which would cause other problems, but I
would rather be corrected now if my thinking is
flawed.

Your advise appreciated.


Umm... How about option 3...

Just touch() the file in a while/foreach loop

<important>
I *think* it will just set the mod/access time if the file exists and create an empty file if it doesn't. Might want to test to be sure though just to make sure it doesn't wipe the file, but I don't think it does.
</important>

This is assuming that the mod/access time isn't used for anything else so if it's randomly updated it won't matter.

You save a file_exists() call this way too.

Ed

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux