Solved

file cuttin

Posted on 2000-04-10
15
181 Views
Last Modified: 2010-04-02
implementation of a program to cut any files(zip,com,exe)to a desired size?
0
Comment
Question by:babs02_99
  • 6
  • 4
  • 3
  • +1
15 Comments
 
LVL 22

Expert Comment

by:nietod
Comment Utility
This sounds like it is for the windows or DOS platform.  In that case, an OS-specific solution would be easiest.   For DOS you can open the file and seek to the position where you want the file to end, then just write 0 bytes at that position.  That truncates the file at that position.

In windows you open the file and seek to the postion where you want the file to end, then you just call SetEndOfFile() to truncate the file at that position.

continues.
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
Those methods will be the fastest, but they are platform-specific and so cannot be ported to other platforms.   For a portable solution you can open the file for reading using an fstream object and read the portion to be "retained" into memory.  the close the file and reopen it for writting (truncating the existing file) and write out the information from the copy in memory.

If the length of the file to be saved is too long to reasonably store in memory, then you can use a 2nd file to store it.  In this case you woulld copy the information from the first file to a 2nd file in small chunks.  Then you would reopen the first file for writting and truncate it.  Then you would copy information from the 2nd file back to the first.   Then you could delete that 2nd file.

I can provide more details, if neeed, if you can indicate what sort of solution might be best for you.
0
 
LVL 9

Expert Comment

by:Pacman
Comment Utility
babs,

just because I'm curious: why do you want to cut exe and zip-files ?
0
 

Author Comment

by:babs02_99
Comment Utility

well,what i want is a method to cut files into a no. of smaller files.
say,there is a file of size 6mb & if the user specifies the cuttin size as 1.2 mb,then the result is 5 files of size 1.2 mb.
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
babs02_99, you have rejected my answer with no expanation of why.

You have presented new facts that were not present in the question.  

You still have not answered what OS this is for.

If I answer again, do I have any sort of assurance you won't reject my answer again?
0
 
LVL 9

Expert Comment

by:Pacman
Comment Utility
you have to copy the file into one ore more files.
first get the number of parts.
then it's a simple loop like this

for (i=0; i<nNumberOfParts; i++)
{
    // open new file for writing
    // read 1.2 MB from source file
    // write 1.2 MB to new created file
    // close new created file
}

// read the rest of source file
// write to last part file

0
 
LVL 9

Expert Comment

by:Pacman
Comment Utility
PS: what you want is file splitting not cutting ...
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 22

Expert Comment

by:nietod
Comment Utility
babs, what is happening to this question.
0
 

Author Comment

by:babs02_99
Comment Utility
well,it is for the dos platform.
i tried implementing it.(actually in c).
it works with a c source file,but not with exe/com files.
the file manipulation was done in the binary mode.

the program shows invalid sizes for exe/com files.
and finally sorry for not following up.
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
Can you post the code you used?

If it works with text files (source code files) and not with binary files (exe/com) you probably have the file opened in text mode, not binary mode.   (I need to see the code to be sure and to know how to fix it for you case.)
0
 
LVL 1

Accepted Solution

by:
guoching earned 50 total points
Comment Utility
Please check out my homepage, I make a
whole page to explain the program. You may download the source code and .exe file from there. Source written in C, will work in dos.
0
 
LVL 1

Expert Comment

by:guoching
Comment Utility
Please check out my homepage, I make a
whole page to explain the program. You may download the source code and .exe file from there. Source written in C, will work in dos.
http://guoching.virtualave.net/exfaq.html
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
gouching, have you read the question history?  

In addition, this question has been inactive for more than a month.  We are waiting for the client to reply.  If the client hasn't replied in a month it is safe to assume he/she has lost interest.  Its not a good idea to answer dead questions.  If you really think you have somethign to add, then post a comment instead.
0
 

Author Comment

by:babs02_99
Comment Utility
Answer accepted
0
 

Author Comment

by:babs02_99
Comment Utility
sorry for not following up...as i was trying to solve it myself....
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now