Solved

file cuttin

Posted on 2000-04-10
15
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

733 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