Borrar filtros
Borrar filtros

Delete last line of a .txt

8 visualizaciones (últimos 30 días)
jose bernardo
jose bernardo el 16 de Nov. de 2013
Respondida: Walter Roberson el 16 de Nov. de 2013
Hello:
I have a file.txt (various lines of strings) and I want that when I push a button "pushbutton1", the last line of this file.txt will be deleted.
Thanks for your help

Respuestas (1)

Walter Roberson
Walter Roberson el 16 de Nov. de 2013
Unfortunately MATLAB does not support the operating system operations needed to truncate a file. Would replacing the deleted section with blanks be acceptable?
The operating systems themselves do not support any operations to insert or delete text inside a file, or to modify text (exception: if the modification is exactly the same size as the original). The operating systems do support truncating files, but MATLAB does not make that available.
Thus if one wants to change a text file, the strategy is to open a new file, copy the original file over to the new file until one gets to the part that needs to be changed, write out the changed text, and then resume copying the input file to the output file. After everything is done, you may rename the output file to the name of the original file.

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by