473,322 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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
Oct 22 '08 #1
1 4599
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: orit | last post by:
I have the following xml file: <?xml version="1.0" encoding="utf-8" ?> <course id="2555" title="Developing Microsoft .NET Applications for Windows (Visual C# .NET)" length="5 days"...
11
by: KarimL | last post by:
Thanks for your advices... but i need to get the Image height because i dynamically resize the height of my webcontrol based on the image height. More i just have the url (relative parth) to the...
2
by: Praveen | last post by:
Hi All, I have made a webservice in C# and it works fine in my machine. I ran into a crazy problem when I wanted to deploy it in windows 2003 server. I have run "aspnet_regiis.exe -i" to make...
0
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
0
by: sags | last post by:
Hi , Iam a new uesr of this group. I have a small doubt . Iam using the code mentioned below to retrive the data from tab delimited text file ., but Iam getting all the columns of the text file...
6
by: Greg Collins [Microsoft MVP] | last post by:
If I go into IIS and change the default 404 error page to an ASPX page, is there any way to then identify the url that was typed in that caused the custom 404 page to be loaded? If so, how do I do...
17
by: blufox | last post by:
Hi All, Can i change the execution path of methods in my process at runtime? e.g a()->b()->c()->d()->e() Now, i want execution to be altered at runtime as -
185
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will...
2
by: Eric Sosman | last post by:
Eric Sosman wrote: Never mind; I see now what I overlooked on first reading: Still, it might be better to return a pointer to a dynamically- allocated region whose size is *known* to be...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.