Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file delete

Status
Not open for further replies.

sagn

Programmer
Jun 7, 2001
166
US
Hi

I want to have my program delete a file if it already exists and then reopen it. In the process I expect the time stamp of the file to change from t0 to t1.
So that:
before program run file X.txt 2/27/2007 exists
Run program
1) delete X.txt
2) Open X.txt so that
X.txt 2/28/2007 exists


I have tried to
OPEN(NOUT,FILE=F)
close(NOUT,STATUS='DELETE')
and then reopen in hopes of having the create data change
when I view the file details (using Windows XP).

However, even though the file is deleted and recreated
it has the same time stamp as the original (2/27/2007 in above example).

If I put a point break after the CLOSE and wait a sec before the file is recreated the time stamp is correct.

I have ALSO tried OPEN(NOUT,FILE=F,STATUS='REPLACE')

And the timestamp is still not updated. Is there anyway
to do this ther than deleting the files before running the program?

Thanks


 
You could try
Code:
str = 'del ' // filename
call system (str)
Depends on which compiler you're using. Some compilers have functions which will delete files.
 
yeah thanks

I guess I will have to try a system call.
It just seems silly to me to have a REPLACE option in the OPEN statement which in effect gives the same result as the 'UNKNOWN'
option.

thanks
 
????
Why not just open the file

open(nout,file='x.txt',status='replace')

This would just replace your existing file with a new x.txt. If it does not exist prior to the open statement it is buildt anew.

You might even omit the status-clause and just start to write data to this file, then a new file x.txt is created, superceding the old one if existent.

Norbert
 
I tried the replace option (see my post) but the date of the file remained unchanged.


And therein lies the problem :)


 
still ???

I tried the following prog on a file that existed for a long time in my directory (abfolge.txt)


program testopen
open(unit=10,file='abfolge.txt',status='replace')
rewind 10
write (10,*)'this is a nonsense line'
close (unit=10)
end

After the prog ran the file had the date of creation set properly (March 1st, 20.38 local time). It did so on a second run even when I did not do any output to the file.

Norbert
 
figures

Funny.. because, believe it or not,
I manually deleted the files.. you know by highlighting and deleting..
and ran the code immediately after...

the files created had the OLD time stamp!

Now if I wait a few minutes.. the files created actually have the correct timestamp!

It's as if there is some sort of ghost in memory or something...

is that odd or what?
 
windows XP, Compaq Visual Fortran Professional 6.6.a
 
sagn,

that is exactly tha same as I use - and I have no such problem as yours. I know, this does not really help, but still....

Norbert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top