Solved

file cuttin

Posted on 2000-04-10
15
183 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
ID: 2700025
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
ID: 2700046
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
ID: 2703447
babs,

just because I'm curious: why do you want to cut exe and zip-files ?
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:babs02_99
ID: 2706730

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
ID: 2707402
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
ID: 2710730
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
ID: 2711350
PS: what you want is file splitting not cutting ...
0
 
LVL 22

Expert Comment

by:nietod
ID: 2759248
babs, what is happening to this question.
0
 

Author Comment

by:babs02_99
ID: 2759368
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
ID: 2759394
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
ID: 2878011
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
ID: 2878015
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
ID: 2878181
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
ID: 2903273
Answer accepted
0
 

Author Comment

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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

808 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