473,396 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

FileInfo.Delete fails to remove file

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
Nov 20 '05 #1
10 7283
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" <al***@sunwave.net> wrote in message
news:eo**************@TK2MSFTNGP12.phx.gbl...
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

Nov 20 '05 #2
* "Allen" <al***@sunwave.net> scripsit:
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>)'?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
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

Herfried K. Wagner [MVP] wrote:
* "Allen" <al***@sunwave.net> scripsit:
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>)'?


Regards - OHM# OneHandedMan{at}BTInternet{dot}com
Nov 20 '05 #4
* "One Handed Man [ OHM# ]" <OneHandedMan{at}BTInternet{dot}com> scripsit:
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?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5
Yes, we(i)/he must have missed something
Herfried K. Wagner [MVP] wrote:
* "One Handed Man [ OHM# ]" <OneHandedMan{at}BTInternet{dot}com>
scripsit:
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?


Regards - OHM# OneHandedMan{at}BTInternet{dot}com
Nov 20 '05 #6
* "One Handed Man [ OHM# ]" <OneHandedMan{at}BTInternet{dot}com> scripsit:
Yes, we(i)/he must have missed something


Thank you for the information!

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #7
Do you have any thoughts on this Herfreid ?

Regards OHM

Herfried K. Wagner [MVP] wrote:
* "One Handed Man [ OHM# ]" <OneHandedMan{at}BTInternet{dot}com>
scripsit:
Yes, we(i)/he must have missed something


Thank you for the information!


Regards - OHM# OneHandedMan{at}BTInternet{dot}com
Nov 20 '05 #8
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
Nov 20 '05 #9
Funny enough though, I cant get that to work either, whats going on ?

Allen wrote:
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
Nov 20 '05 #10
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
Allen wrote:
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
Nov 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David Turner | last post by:
I have created an ASP.NET page that uses the System.IO.DirectoryInfo.GetFiles() method to get a list of files in a specific directory on our web server. (I simply use this list to build some...
2
by: John Bowman | last post by:
Hi All, ..NET 1.1... I'm wondering if there is any approach more convenient to get a list of FileInfo objects than the following. For example, if I wanted to get 1 list of all the Exe's and all...
1
by: Tim Failes | last post by:
This seems a trival question, but I cannot get it to work properly... Essentially my question is, how can I create a text file, and guarantee it is given the current date/time as the Creation Time?...
2
by: tshad | last post by:
I am having a problem with my Datagrid that displays my Files via GetFiles() If I use a HyperLinkColumn - I can use the column name "Name" which is what the result from GetFiles(). ...
6
by: sam_cit | last post by:
Hi Everyone, I'm using remove() function to delete a file, and i observed the following behavior, Concerned file : sample.txt Operation : i open the file in read mode and don't close the...
0
by: dolphinearth | last post by:
Hi. I have a strange problem around DirectoryInfo and FileInfo of C# (c- sharp). I have a File Watcher which automattically imports files from a network drive to a directory on the local...
5
by: Tom P. | last post by:
I am having the following problem: I create a FileSystemWatcher and wait for events. When the event does happen I refresh a FileSystemInfo list and set properties accordingly (IsFile, IsDir,...
6
by: tinman77 | last post by:
Hello, I'm having a terrible time using the functions finfo_open and finfo_file. I'm using PHP 5 on IIS 5.1 and Windows XP. I have enabled php_mime_magic.dll and php_fileinfo.dll and also added...
6
by: fyitang | last post by:
hi guys, here is the sample: string strFileFullName = ""; try { FileInfo currentFile = GetOneFile("some directory"); strFileFullName = currentFile.FullName; // do someting...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.