473,791 Members | 3,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read and write last few bytes of a large text file

16 New Member
Hi Friends,

I am trying to get the last 50 Mb of a large Text file(Over 2 GB) using VB. I have to add this to an Access form so that when the user clicks the button a pop up window asks for the source of the text file and the destination of the output file and then it saves only the last 50 MBytes of the file to the output location. I am not that good in VB programming. I would appreciate if anyone can help me on this?


Thanks,

Arthur
Oct 13 '08 #1
10 3281
NeoPa
32,579 Recognized Expert Moderator MVP
What have you managed so far Arthur?

I'm happy to help - but I don't see myself spoonfeeding. You will need to be checking help files etc, but I can point you at where to look.
Oct 13 '08 #2
sarthur
16 New Member
What have you managed so far Arthur?

I'm happy to help - but I don't see myself spoonfeeding. You will need to be checking help files etc, but I can point you at where to look.

Hi Neopa,

Thanks for your help. I am trying to get only the last 50 MB's of a large file. I read a lot of articles about reading and writing into files using vb and have created a program. The problem is that when I try to run it I get an overflow error. I think its because of the huge file size(more than 2 Gb) and also because I am trying to get the entire contents in a string. I know a string datatype has some limitations. What I meant help doesn't mean that I need spoonfeeding. What I need is some kind of advice, guidance or even if you could suggest me materials to look at. I have come to experts like you as a final resort and to get some guidance. I appreciate all your efforts to help me with my previous post and Im glad that experts like you spend their precious time to guide people like me. I know that there should be some other efficient way of getting that data. I would appreciate any kind of help from you or any of the other experts here on this. I am attaching the code below.

Thanks and regards,

Arthur


Expand|Select|Wrap|Line Numbers
  1. Private Sub GetFile()
  2.  
  3.   Dim intFF_In As integer
  4.   Dim intFF_Out As Integer
  5.   Dim strRead$
  6.   Dim SourceFile As String
  7.   Dim DestinationFile As String
  8.  
  9.  
  10.  
  11.   intFF_In = FreeFile
  12.   sourcefile = filename
  13.   DestinationFile = filename  
  14.  
  15.   Open SourceFile For Binary Access Read Lock Read Write As intFF_In
  16.  
  17.  
  18.   While Not EOF(intFF_In)
  19.  
  20.  
  21.  
  22.  
  23.     If Len(Dir(strOutFile)) > 0 Then Kill strOutFile
  24.  
  25.     intFF_Out = FreeFile
  26.     Open DestinationFile For Binary Access Write Lock Read Write As intFF_Out
  27.  
  28.       strRead = String(LOF(intFF_In), " ")
  29.  
  30.       Get #intFF_In, LOF(intFF_In)-52428799, strRead
  31.  
  32.       Put intFF_Out, , strRead
  33.  
  34.  
  35.  
  36.     Close intFF_Out
  37.  
  38.   Wend
  39.   Close intFF_In
  40.  
  41.  
  42. End Sub
  43.  
Oct 15 '08 #3
Krandor
50 New Member
The string variable has a 2 gig limitation. So if your file is 2 gigs +, there is your overflow problem.

I'm a little rusty on the exact syntax, but there is a way to input part of the file beginning at a set point (at character 1,000,000 for example). If all you want is the last bit, there is no point in sucking in the entire file into your variable.

You are pretty close using the LOF so I would Google on LOF Input for VBA to see what shows up.
Oct 15 '08 #4
NeoPa
32,579 Recognized Expert Moderator MVP
Arthur,

I need some time to look up some old code to give the right pointers here. I will come back when I can. Once the relevant commands and statements are all understood it should be quite doable. My only worry at this stage is whether or not the interface can actually handle file accesses >4GB.
Oct 16 '08 #5
NeoPa
32,579 Recognized Expert Moderator MVP
2GB is not only a string limit (this could be got around), it is also a limit on accessing the file.

Your code is fine as far as it goes, only you should be looking at handling multiple, more sensibly sized, records. A MB buffer is normally efficient enough, but you'd want to "Seek" to the start point, rather than process through reading all the data up to it.

All this is moot I'm afraid though as, without a facility to Seek to the point you're interested in, it won't work anyway :(
Oct 16 '08 #6
NeoPa
32,579 Recognized Expert Moderator MVP
It might be possible (you will need to experiment yourself) to adjust the file position without using an explicit Seek, by use of multiple Reads.

Let us know how you get on with this.
Oct 16 '08 #7
FishVal
2,653 Recognized Expert Specialist
Hello, gentlemen.

I think the following will cover the whole issue.

Different file systems specifications
How To Seek Past VBA's 2GB File Limit

Regards,
Fish

P.S. Long live google. ;)
Oct 16 '08 #8
NeoPa
32,579 Recognized Expert Moderator MVP
That's a neat solution Fish. I'm not sure everyone will be confident enough to try it, but it's there anyway.

It would certainly be my choice if I had a need for it :)
Oct 16 '08 #9
sarthur
16 New Member
Thanks for all your help friends.Sorry for my late reply. I think Fishvals method sounds promising. I will try that and see how that goes.

Thanks,

Arthur
Oct 17 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
7775
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a DB and display it onscreen. No matter which way I open the file, convert it to Unicode/leave it as is or what ever, I see all single bytes ok, but double bytes become 2 seperate single bytes. Surely there is an easy way to convert these mixed...
0
5683
by: Ahmed A. | last post by:
This will be very helpfull for many! Using RichTextBox Read/Write Unicode File http://www.microsoft.com/indonesia/msdn/wnf_RichTextBox.as p Private Function ReadFile(ByVal myfile As String) As String Dim myFileStream As Stream = File.Open(myfile, FileMode.Open)
35
11497
by: RyanS09 | last post by:
Hello- I am trying to write a snippet which will open a text file with an integer on each line. I would like to read the last integer in the file. I am currently using: file = fopen("f.txt", "r+"); fseek(file, -2, SEEK_END); fscanf(file, "%d", &c); this works fine if the integer is only a single character. When I get into larger numbers though (e.g. 502) it only reads in the 2. Is there
0
4757
by: phplasma | last post by:
Hey, I am currently attempting to implement a multi-threaded C# socket, using SSL (.pem file/certification/private key combo) server using Visual Studio C# Express. I have successfully made the client application establish a connection, and send data, which appears in plain, de-crypted text on the server - this works.
8
2237
by: paraidy | last post by:
Hi all, as from object i need to read all byte from a file example c: \myphoto.jpg and recreate the file with another name to another directory c:\photo\recreatedphoto.jpg can someone write a small example to do it? thx a lot men :)
2
5458
by: Kevin Ar18 | last post by:
I posted this on the forum, but nobody seems to know the solution: http://python-forum.org/py/viewtopic.php?t=5230 I have a zip file that is several GB in size, and one of the files inside of it is several GB in size. When it comes time to read the 5+GB file from inside the zip file, it fails with the following error: File "...\zipfile.py", line 491, in read bytes = self.fp.read(zinfo.compress_size) OverflowError: long it too large to...
9
3851
by: vineeth | last post by:
Hello all, I have come across a weird problem, I need to determine the amount of bytes read from a file, but couldn't figure it out , My program does this : __ file = open("somefile") data = file.read() print "bytes read ", len(data) ---
4
1315
by: Curious | last post by:
I have a file to which I'll need to at first read until it locates the last line of string. According to content of the last line of string, I'll need to write something to this file right after the last line of string. This requires that I'll need a StreamReader at first (to read one line at a time), until the last line is read. Then I'll need a StreamWriter to point to the end of the file, and
4
3418
by: Keith G Hicks | last post by:
I'm trying to read a text file and alter the contents of specific lines in the file. I know how to use streamreader to read each line of a file. I'm doing that already to get the data into a database. What I need help with is on how to locate a specific line in the file, change it and then save the updated text file. Can anyone help me out or point me to a site that explains this clearly? Here's part of my code that reads the contents of...
0
9515
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10427
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10155
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9995
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.