Getting path from a file pointer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Moot

    Getting path from a file pointer

    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
  • Rzzap

    #2
    Re: Getting path from a file pointer

    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

    Comment

    Working...