• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

file cuttin

implementation of a program to cut any files(zip,com,exe)to a desired size?
0
babs02_99
Asked:
babs02_99
  • 6
  • 4
  • 3
  • +1
1 Solution
 
nietodCommented:
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
 
nietodCommented:
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
 
PacmanCommented:
babs,

just because I'm curious: why do you want to cut exe and zip-files ?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
babs02_99Author Commented:

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
 
nietodCommented:
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
 
PacmanCommented:
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
 
PacmanCommented:
PS: what you want is file splitting not cutting ...
0
 
nietodCommented:
babs, what is happening to this question.
0
 
babs02_99Author Commented:
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
 
nietodCommented:
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
 
guochingCommented:
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
 
guochingCommented:
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
 
nietodCommented:
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
 
babs02_99Author Commented:
Answer accepted
0
 
babs02_99Author Commented:
sorry for not following up...as i was trying to solve it myself....
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 6
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now