Solved

file cuttin

Posted on 2000-04-10
15
184 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to convert c++ code to Android App 3 109
SNMP error No Such Object available on this agent at this OID 3 305
Unable to start eclipse ? 17 154
C++ Code Issue 4 25
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

827 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