RE: Changing the size of a file.

Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: May 2008
Posts: 3
Reputation: MatrixCA is an unknown quantity at this point 
Solved Threads: 0
MatrixCA MatrixCA is offline Offline
Newbie Poster

RE: Changing the size of a file.

 
0
  #1
May 9th, 2008
Does anyone know how to change the value of FS.Length? I keep getting that it's read only.

I need to read a file, let's say it's 100 bytes in size. After some data manipulation, the file becomes 40 bytes. When I write the file back , it writes the 40 bytes plus the remainder of the file thus the file remains at 100 bytes.

I know that if I read the file as File A, write it back as File B and then delete File A would probably work but I want to overwrite the existing file.

I have noticed the the value of FS.Length does not change although the data string that I am writing is 40 bytes.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 3
Reputation: MatrixCA is an unknown quantity at this point 
Solved Threads: 0
MatrixCA MatrixCA is offline Offline
Newbie Poster

Re: Changing the size of a file.

 
0
  #2
May 10th, 2008
Here's what I have so far:

fs = f.open
lBytes = fs.Length

Dim fileData(lBytes) As Byte
fs.Read(fileData, 0, lBytes)
ModifyFileData(fileData)
fs.Close()

fs = f.OpenWrite
fs.Write(fileData, 0, fileData.Length)
fs.Close()

The code may not be pretty but it's a start.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 3
Reputation: MatrixCA is an unknown quantity at this point 
Solved Threads: 0
MatrixCA MatrixCA is offline Offline
Newbie Poster

Re: Changing the size of a file.

 
0
  #3
May 10th, 2008
I was able to resolve the problem.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 523 | Replies: 2
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC