Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Reverse the contents of a file

Posted on 2014-01-09
5
Medium Priority
?
256 Views
Last Modified: 2014-01-19
I have some file types that I need to Reverse the content.
So that the Last byte is the First byte, and the first byte is now the last byte.

Sort of like if you used a FILO buffer as you read and then resave the file byte by byte.

example if the file has this text in it...
ETARDEEF LAUNAM11 EDIRREVO ETARDEEF LAUNAM01 EDIRREVO ETARDEEF LAUNAM9 EDIRREVO ETARDDEF LAUNAM8 EDIRREVO

after it is reversed it will look like this.

OVERRIDE 8MANUAL FEDDRATE OVERRIDE 9MANUAL FEEDRATE OVERRIDE 10MANUAL FEEDRATE OVERRIDE 11MANUAL FEEDRATE

The files can be up to 32GB in size and contain binary data.

( I don't need to reverse the actual Binary bits)
If I read the first Byte of the file and it is 00010001 then I still want to write 00010001 but instead of it being the first byte, it will now be the last byte.

I could code a program to  do something like this: with 3 files...
Source file - file to be reversed
Temp File - temporary use
Destination File - results of reversal

1.) Get next Byte from Source
2.) Write Byte to Temp
3.) Get Entire content of the Destination
4.) Copy to end of Temp
5.) Dispose of Destination
6.) Copy Temp to Destination
7.) Dispose of temp

Repeat till all Bytes of the Source have been read.

When done the destination file will now be the reverse of the source file
But doing it byte by byte like this will take a long time...

I wonder if there is an Easier or Quicker way.

I have access to
VB.net VB2010 express  or VB2013 express  

I would need to be able to Select the Source File
Choose a destination File

then reverse the file.

Sample code and Logic would be very helpful.
0
Comment
Question by:vpcnc
[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
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:HooKooDooKu
ID: 39769660
File IO sounds like a killer with that approach.  
You might as well just use two files (one input one output).  

1. Seek to the end of the input file -1.
2. Read a byte, write a byte
3. Seek to the end of the input file -2
etc

But IMHO, it would be better to do the reversal in memory.  The optimized thing would be to read the entire input file into memory, reverse the data in memory, and write the whole memory block back out.  But that approach has the obvious drawback that you likely do not have 32GB of physical memory.  (That approach might still work, but only with a lot of disk swapping at the OS level).

But with limited resources, you need a way to break the process down into smaller chunks.  So you might try to process the file in 1MB blocks.
1. Seek to the end of the file - 1MB
2. Read 1MB into memory
3. Reverse the 1MB block in memory.
4. Write the 1MB block of memory to destination file.
5. Seek to the end of the file - 2MB.
etc
Of course you have to deal with the fact that the file will not be an even number of 1MB blocks, so you'll have to come of with a way of dealing with that last <1MB block.
0
 
LVL 1

Author Comment

by:vpcnc
ID: 39777052
The Logic sounds workable
can you provide Code examples to go along with your Logic plan?

I have access to (VB.Net 2010 Prefered)  or VB.net 2013

File Selection Popup to select the file to be reversed
to select the Destination file to save the results to

Code to Seek to the end of the file and read 1MB into memory.
Code to reverse the contents of Memory
Code to Output memory to the destination file
0
 
LVL 16

Expert Comment

by:HooKooDooKu
ID: 39779509
The nature of this question very much makes it look like a homework assignment.

Understand that EE's 'terms of use' do not permit experts to provide solutions to academic questions (i.e. experts are not allowed to do other's homework).

I feel like I've already pushed the limits of what EE allows by providing you an outline of how to complete this assignment.  

As such, I'm going to have to limit further responses to answering specific questions... questions best asked by providing coding samples of what you've got so far where experts here can help with questions like 'why won't line 25 compile', or 'why does the program raise an error at line 10', or 'what function can I call to determine a file size'.
0
 
LVL 1

Accepted Solution

by:
vpcnc earned 0 total points
ID: 39779904
Ha ha ha ha ha  Home work assignment....  
you make me laugh...  

If this was VB6, I'd be done with it..  
but File IO on VB.net is much different than it was in VB6. As I have Zero experience with doing File IO on .net, I was hoping that a person with more experience, that perhaps has done File IO a thousand times..  

would be able to provide an example..  
cut and paste from something that you've done like the back of your hand...

Nope,  Not these Experts...   not on a Paid Service..   Oh my gawd, it might be a kid asking for help...

Do you really think they'd pay for this service to get Homework help?  honestly?


Sure I can waste my time searching the net.. But I paid for this service here..
Why did I pay for this service if I'm going to do all my own internet research?

Refund me my Money!
Ever question I ask, I get he same BS from the "Experts"


Duh.. maybe you should do your own research...

and then they expect their Points...
I helped you by making you do your own research..  I posted links to a site you can go visit...
where are my points....    
I need points so I can show how smart I am...
I'm so smart I answered 100 questions today....  Look at my Points total...

Any idiot can google and post a link relative or Not to the subject...
That doesn't make you an "Expert"

I'm a business executive..  at a small company,  in my Mid 50's,  
I wear many different Hat's,  my time is better spent doing other things..
In the real world,  Points mean absolutely nothing....
I don't care how many points you got here...  what counts is "Show me what you know..
show me what you can do for me...  

When I hire someone,  I give them a hands on Test..
Here's a box of Parts..  30 different pieces or so in the box..

What can you tell me about each item in that box..

In that box are
Some mechanical, some pneumatic, some hydraulic, some electronic and electrical...
Some pieces would get assembled together...

If they have the experience they claim to have, they will know what every item is, what it's used for,  maybe they will even know that it's defective and that's why it in the box..
or they will describe how to connect it.  
or they would even put some of the pieces together...

Now thats a real test of an "Expert"

It the same here...  this is my box test...  I asked a question..  give me an "Expert" answer.

That's why I decided to Pay for this service, and expect to get direct answers.
Not this lame  response -
Uh.. well you sound like a child doing a homework assignment and I can't help you.

Fine,  refund me my Money,  I'll spend it to get a REAL expert to answer my questions..
instead of spending it on Points chasers..

Close this Question, I'll seek my answer elsewhere...
0
 
LVL 1

Author Closing Comment

by:vpcnc
ID: 39791932
already stated in my post..
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

636 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