Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

SynLogek

Shrinking Files in C

This topic is 6226 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well I''m not sure if its possible by the looks of it, but is it possible to open an existing file in C and delete a part of its contence? I''m dealing with files that are up to 500mb so the idea of recreating the file with just the stuff i want is a bit of a slow process. If its even possible to remove just the data at the end of the file to make the file smaller is fine but I can''t even do that. Any help would help! Thank you, Phil.

Share this post


Link to post
Share on other sites
Advertisement
You could write a program that read the file and writes only the wanted contents to another file, before deleting the original file. Should be pretty easy to implement.

Share this post


Link to post
Share on other sites
Read the file? And how do you expect to do that? A 500Mb file will not fit into most peoples memory, so "reading" it is a bit out of the question. I understand what you mean though SynLogek, all though I don''t know how to do it You trying to impliment a type of archive?

Share this post


Link to post
Share on other sites
Ok, I''ve just searched a bit on this ( I could do with knowing a bit about it aswell ), and I have found a few functions that could do it. Firstly, there is WriteFileEx(), which can write data anywhere in a file, and SetEndOfFile() which can increase or decrease the size of a file. Look them and related functions/structures up in the msdn.

Hope that helps

Share this post


Link to post
Share on other sites
Thanks for the help. Those functions will help a lot. But is there any low-level functions that can be used only in dos that might be platform independent? That is my ultimate goal.

Share this post


Link to post
Share on other sites
Why only C/dos? I suggest you grab Win95 and a Windows C/C++ compiler, dev-cpp is a great free one! Then if you follow the windows documentation, you can port it to virtually every Windows platform. Windows will own more than 50% of the OS market for the next 10 years or so...why not...go with winblows!

Share this post


Link to post
Share on other sites
Well I still prefer to make it cross-platform compatable. All the code so far is. Its just shrinking the file. I''m using Visual C++ 6 and using those functions mentioned early work awsome, its just you have to be on a windows platform.

I''m just being a pain.

But if anyone knows which functions will work in dos to shrink a file, I still can''t do it!

Share this post


Link to post
Share on other sites
Oh ya, I found it.

int chsize( int handle, long size );

or

int _chsize( int handle, long size );

Shows what a bit of persistance does. Had to find it in the header directly. But then realized its also in the msdn library.

Thank you all for your help!

Share this post


Link to post
Share on other sites
Why can''t you just read part of the file (say 1 Meg) at a time, remove whatever data you don''t want, then write it to another file? Reading it in chuncks should reduce the memory requirements...

Share this post


Link to post
Share on other sites
Well, I didn''t want to have to rename the file everytime. And transfering that much data is a pain and very slow. The file is a archive of other files, so rearranging the data isn''t so hard using the base level functions.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!