FileInfo.Delete fails to remove file

  • Thread starter Thread starter Allen
  • Start date Start date
A

Allen

When using FileInfo to delete a file, the file remains in the directory (not
deleted)

Dim foo as New FileInfo(strFileToDelete)
Try
foo.Delete()
Catch ex as IOException
'Open file handler
End Catch

The file exists and is valid. The path exists and is valid. No file
attributes are set except for ARCHIVE. I have permission to read and write
to the directory.
No exception is thrown (ex = Nothing) yet the file is not deleted from the
directory.
Any suggestions?
Thanks in advance.
Allen
 
Hi,

1) try using ex as exception instead of ioexception.
2) What do you get for foo.exists ?
3) Last option is File.Delete(strFileToDelete)

Ken
 
* "Allen said:
When using FileInfo to delete a file, the file remains in the directory (not
deleted)

Dim foo as New FileInfo(strFileToDelete)
Try
foo.Delete()
Catch ex as IOException
'Open file handler
End Catch

The file exists and is valid. The path exists and is valid. No file
attributes are set except for ARCHIVE. I have permission to read and write
to the directory.
No exception is thrown (ex = Nothing) yet the file is not deleted from the
directory.

Does it work if you use 'System.IO.File.Delete(<filename>)'?
 
I can confirm that this does NOT work and that no exception is thrown. I
dont know why though. It may be a chaching issue ?

Regards - OHM
Does it work if you use 'System.IO.File.Delete(<filename>)'?

Regards - OHM# OneHandedMan{at}BTInternet{dot}com
 
* "One Handed Man said:
I can confirm that this does NOT work and that no exception is thrown. I
dont know why though. It may be a chaching issue ?

You are referring to the 'FileInfo' class?
 
To All
The try catch exception is ex = Nothing (no exception is thrown)
foo.Exists = True

I shall try File.Delete(strFileToDelete) although this step is somewhat
counter intuitive when dealing with an inherited class such as FileInfo
(from base class File).

Regards,
Allen
 
Funny enough though, I cant get that to work either, whats going on ?
To All
The try catch exception is ex = Nothing (no exception is thrown)
foo.Exists = True

I shall try File.Delete(strFileToDelete) although this step is
somewhat counter intuitive when dealing with an inherited class such
as FileInfo (from base class File).

Regards,
Allen

Regards - OHM# OneHandedMan{at}BTInternet{dot}com
 
When I tried this I was testing it with a file named test.txt, the system
appended the type .txt so the real filename was called 'test.txt.txt'

hence it did not work. Since then I have re-tried it with FileInfo.Delete()
and File.Delete("filename.txt") and they both work fine.


Regards - OHM

To All
The try catch exception is ex = Nothing (no exception is thrown)
foo.Exists = True

I shall try File.Delete(strFileToDelete) although this step is
somewhat counter intuitive when dealing with an inherited class such
as FileInfo (from base class File).

Regards,
Allen

Regards - OHM# OneHandedMan{at}BTInternet{dot}com
 
Back
Top