File being used

  • Thread starter Thread starter Mohsen Aghazadeh
  • Start date Start date
M

Mohsen Aghazadeh

Do you have any idea of how I can find out if a file in a
directory is being used by a user or application without
trying to open/delete/... the file? (Just getting the
file status)
It would be highly appreciated if you reply me.
 
Do you have any idea of how I can find out if a file in a
directory is being used by a user or application without
trying to open/delete/... the file? (Just getting the
file status)

Did you look at the fileinfo class?
I don't see any information in the attributes about "used".
But why are you not doing after evaluating the attribute information a
\\
try
'open does not matter how a file
catch ex as exeption
'check the exeption
finally
'close file
end try
///
I hope this helps a little bit
Cor
 
Hello,

Cor said:
Did you look at the fileinfo class?
I don't see any information in the attributes about "used".
But why are you not doing after evaluating the attribute
information a
\\
try
'open does not matter how a file
catch ex as exeption
'check the exeption
finally
'close file
end try
///
I hope this helps a little bit

There is a _little_ problem: If the file is not used by an other
application, opening it may change the file date (last access).

;-)
 
Herfried,
This did remind me on a promise I did make last night.
I putted it by the notepad thread,
Then I thought why not test what Herfried said (normaly I don't do that), it
was in one route,
but I was busy with the other things, and I think Fergus and I are both very
quick typers.
Here it is, test it if you want after you did the other one, then the file
is on disk.
\\\\
Dim sr As StreamReader
Dim a As New FileInfo("C:\Armin")
Try
sr = New StreamReader("C:\Armin")
Finally
sr.Close()
End Try

Threading.Thread.Sleep(10000)
Dim b As New FileInfo("C:\Armin")
MessageBox.Show(a.LastAccessTime.ToString & "|" &
b.LastAccessTime.ToString)
////
But you know of course the answer already.

:-))

Or maybe I have another computer than you.
Cor

PS, I left that Doornbos thing for you, yesterday, you said only "NO" so I
thought now you would say only "YES"
:-))
 
Back
Top