View previous topic :: View next topic |
Author |
Message |
DanRRight
Joined: 10 Mar 2008 Posts: 2816 Location: South Pole, Antarctica
|
Posted: Sat Aug 27, 2016 10:51 am Post subject: Open file and close it deleting its content |
|
|
Please remind how to open some file, erase its content if it exists and close with zero size? |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Sat Aug 27, 2016 1:39 pm Post subject: |
|
|
This is one way (NOT SECURE!)
Code: |
open(11,file='xx',status='replace')
rewind(11)
endfile(11)
close(11)
|
This way of truncating a file is not secure because most of the bytes that were originally on the file may still persist on the medium (disk drive, USB flash, etc.). If you are not worried about secrecy, etc., however, this is a simple solution. |
|
Back to top |
|
|
DanRRight
Joined: 10 Mar 2008 Posts: 2816 Location: South Pole, Antarctica
|
Posted: Sat Aug 27, 2016 10:35 pm Post subject: |
|
|
hollymolly...Good that I stopped and decided to ask the group. I'd easily lost the rest of the night trying to find this. Many thanks Mecej4 |
|
Back to top |
|
|
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Thu Sep 08, 2016 7:48 am Post subject: |
|
|
To remove the file you can use
Code: |
close(11,status='DELETE')
|
_________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
Back to top |
|
|
|