LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Prepending to beginning of file

This is a general question about files and file systems ... not necessarily about LabVIEW.

 

Let's say you have a very large file.  The file format doesn't really matter.  And you want to append some data to the beginning of the file (i.e. "pre-pend").  Is there any way to do this WITHOUT reading the entire file into memory and then re-writing the entire file?  I can't think of a way to do it in LabVIEW.  

 

Is there any way to do it using OTHER programming languages?

 

EDIT:  I understand there are a lot of "workarounds" to this problem.  For example, I currently write a bunch of "blank" bytes to the beginning of my file, which I can then go back and overwrite as needed.  But my question is more about the ABILITY to do this.  I am really curious if there is any feasibnle way to do it using other programming languages ...  e.g. could we tell the file system that the "start location" for the file has moved?  I suspect that is not possible?

http://www.medicollector.com
0 Kudos
Message 1 of 11
(1,854 Views)

You need Set File Position function.

 

So after opening the file reference (using Open/Create/Replace File function) you need to use Set File Position function and then use Write to Text (or Write to Binary) function.


I am not allergic to Kudos, in fact I love Kudos.

 Make your LabVIEW experience more CONVENIENT.


0 Kudos
Message 2 of 11
(1,849 Views)

I am pretty sure that using "set file position" won't work.  That simply sets the offset to where you will write.  If you set that to ZERO, it will simply overwrite the bytes at the beginning of the file.

http://www.medicollector.com
0 Kudos
Message 3 of 11
(1,844 Views)

@josborne wrote:

I am pretty sure that using "set file position" won't work.  That simply sets the offset to where you will write.  If you set that to ZERO, it will simply overwrite the bytes at the beginning of the file.


My bad...Smiley Sad You're correct..!! It will actually overwrite the file, and you want it to be prepend, that too without reading the file...!!

 

Is it a text or binary file you're working with??


I am not allergic to Kudos, in fact I love Kudos.

 Make your LabVIEW experience more CONVENIENT.


0 Kudos
Message 4 of 11
(1,839 Views)

Currently, I am looking at text files.  But  the question is generic (since all files are binary :-)).  

http://www.medicollector.com
0 Kudos
Message 5 of 11
(1,836 Views)

This might be done on the operating system level, i.e. you could try to manipulate an FAT (if the file system has one) and create a fragmented file.

 

Cheers

Edgar

0 Kudos
Message 6 of 11
(1,827 Views)

@josborne wrote:

Currently, I am looking at text files.  But  the question is generic (since all files are binary :-)).  


Ok, well prepending cannot be done without reading the entire file, I was wondering if Preallocated Read from Binary File function (this can help with memory issues) is of any use.. and my intension of asking the file type is, this function is meant for Binary, but you're right all files are binary at deepest level...!!


I am not allergic to Kudos, in fact I love Kudos.

 Make your LabVIEW experience more CONVENIENT.


0 Kudos
Message 7 of 11
(1,826 Views)

Hi josborne,

 

usually you cannot prepend data to a file without copying all the remaining data. (Maybe there exists some exotic filesystem that allows for prepending, but I never have heard of.)

 

You might think about database usage.

You might think about other fileformats (like tdms) to store properties/information in a structured file.

You might think about using two files instead of just a big one...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO
0 Kudos
Message 8 of 11
(1,824 Views)

Another issues is that many file types have format data at the beginning, so prepending ...

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 9 of 11
(1,820 Views)

Thanks everyone.  As suspected, it doesn't seem possible.  

 

Strange, though.  You'd think the underlying file system would allow this.  I understand a bit about file systems.  And it doesn't really seem like it should be that hard.  In theory, the  "pointer" (or whatever it is) that points to the start location of the file would have to change.  And if there is no contiguous "empty" space before that location, you'd just have to fragment and pre-pend multiple chunks.

 

Anyway, this is really a question about file systems (in particularly NTFS), I guess.

http://www.medicollector.com
0 Kudos
Message 10 of 11
(1,810 Views)