Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

splitting a file

Status
Not open for further replies.

wduty

Programmer
Jun 24, 2000
271
US
Is there any win32 way to split a file into two files? I mean doing so "in place".

For example, if I have a 1GB file and I want the first 500MB's to be one file and the second 500MB's to be another file, can it be done?

I can easily do this by getting a file handle, copying the first 500MB to a new file, then copying the remaining 500MB to another new file, and finally deleting the initial file, but this is CPU wasteful when files get really large.

Any help appreciated.
--Will Duty
wduty@radicalfringe.com

 
such operations are always wasteful. If you want to not to be so wasteful, do it in a sepaarte thread with low priority and smaller portions, for example 1MB. Ion Filipski
1c.bmp


filipski@excite.com
 
Yes, but it sounds like you mean performing a copy operation. I'm trying to avoid copying data because the files might be very large.

It's easy to get the first part of a file by putting the file handle where you want the first part to end and doing a SetEndOfFile(). But that essentially deletes the second half. Is there any way to keep the second half as well, and assign it a name in the file system without moving any data?

--Will Duty
wduty@radicalfringe.com

 
I can't understand what does SetEndOfFile to do there? you should just ReadFrom/InsertTo(theese ones are not functions, hust words). Try it by using memory mapped files. Ion Filipski
1c.bmp


filipski@excite.com
 
How would file mapping help? I wasn't aware that you could create a file-system entry with file mappings...

I'm sorry, I think I didn't explain the problem clearly.

I have a third party component which accepts files of a certain format. Meanwhile, I will be receiving files from another process in a temp directory. When these files arrive, I need to send them to the component. However, these files have a custom header which needs to be removed before the component will understand the file. Therefore, I need to somehow remove the header before passing the filename to the component.

I can copy the valid portion of the file to a new file and send the name of this new file to the component but that means copying part of the file. This is do-able but not optimal because the files may be quite large. If the component accepted a file-handle, it would be quite easy becuase I could move the handle to the beginning of the valid file portion, but it unfortunately only accepts a filename.

--Will Duty
wduty@radicalfringe.com

 
there exists function SplitSymbols, I don't know what is that for, but see it. Ion Filipski
1c.bmp


filipski@excite.com
 
I looked at SplitSymbols() but it appears to be associated with PE files (?) (I didn't understand the documentation too clearly).
Thanks though.
--Will Duty
wduty@radicalfringe.com

 
I now understand what do you want. As I understand you want to concatenate directly the cluster with the end of first file with cluster to begin of second file, delete the name of old file... Try to see, maybe there exists some COM objects what doest that. Ion Filipski
1c.bmp


filipski@excite.com
 
I've looked around and not found anything but I will keep looking. The closest thing I've seen so far is something called "reparse-points" which are used with DeviceIOControl() and which supposedly allow you to filter operations on device drivers with custom functionality but I haven't found enough documentation to tell if it is a possible solution.
--Will Duty
wduty@radicalfringe.com

 
but how will you split files on different logical or phisical drivers? Ion Filipski
1c.bmp


filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top