By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,303 Members | 1,260 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,303 IT Pros & Developers. It's quick & easy.

Getting path from a file pointer

P: n/a
The scenario is that I am processing a large text file and moving each
line to one of a number of other files based on some criteria. I have
an array of file pointers with writable files. I have a limitation
where each of these subfiles can only contain a maximum of 8000
lines. Once I reach that mark, I would like to close the current file
pointer and open a new one with an integer increment appended to the
filename.

My problem is that once I have created these file pointers, how do I
then, for an arbitrary pointer, find out what path it points to?
Ideally, I would like to get the current path for the pointer, perform
some string manipulation to get me a new filename, then close it and
open the new file in it's place so that I can continue writing. Seems
like there should be some built-in php function to get the path for a
file pointer, but I can't find it. Anyone know of a way to get this
information?

Thanks,
- Moot
Oct 22 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Moot wrote:
The scenario is that I am processing a large text file and moving each
line to one of a number of other files based on some criteria. I have
an array of file pointers with writable files. I have a limitation
where each of these subfiles can only contain a maximum of 8000
lines. Once I reach that mark, I would like to close the current file
pointer and open a new one with an integer increment appended to the
filename.

My problem is that once I have created these file pointers, how do I
then, for an arbitrary pointer, find out what path it points to?
Ideally, I would like to get the current path for the pointer, perform
some string manipulation to get me a new filename, then close it and
open the new file in it's place so that I can continue writing. Seems
like there should be some built-in php function to get the path for a
file pointer, but I can't find it. Anyone know of a way to get this
information?
Afaik, you can't get this from a resource created from fopen.
You could make a class which has the resource just as one of its
properties, where reading/writing is taken care of by propagating calls
(get/read/open/close) to a the resource, with other functions/properties
to 'remember' the extra data you want.

You could even go as far as to use stream_wrapper_register, in which
case you can largely keep the same code. Only opening of a filename has
to change to opening with your customer wrapper, but normal
fseek()/fwrite()/fclose etc. should work. In that case, you can even
automate the creation of a new file below the surface, just keeping
fwriting to the object, and let it create a new fileresource to write to
on the fly.

--
Rik
Oct 22 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.