FileInfo.Delete无法删除文件 [英] FileInfo.Delete fails to remove file

查看:169
本文介绍了FileInfo.Delete无法删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用FileInfo删除文件时,该文件仍保留在目录中(不是

已删除)


Dim foo为New FileInfo(strFileToDelete)

尝试

foo.Delete()

Catch ex as IOException

''打开文件处理程序

End Catch


该文件存在且有效。路径存在且有效。没有文件

属性被设置,但ARCHIVE除外。我有权读取和写入
到目录。

没有抛出异常(ex = Nothing)但是文件没有从
$ b中删除$ b目录。

有什么建议吗?

提前致谢。

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

推荐答案




1)尝试使用ex作为异常而不是ioexception。

2)你得到什么f​​oo.exists ?

3)最后一个选项是File.Delete(strFileToDelete)


Ken

--------- ---------------

" Allen" <人*** @ sunwave.net>在消息中写道

news:eo ************** @ TK2MSFTNGP12.phx.gbl ...
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...
使用FileInfo删除时一个文件,文件保留在目录中
(没有被删除)

Dim foo为新FileInfo(strFileToDelete)
尝试
foo.Delete( )
Catch ex as IOException
''打开文件处理程序
End Catch

该文件存在且有效。路径存在且有效。除ARCHIVE外,没有设置文件
属性。我有权读取和写入目录。
没有异常被抛出(ex = Nothing)但文件没有从
目录中删除。
有什么建议吗?
提前致谢。
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



*" Allen" <人*** @ sunwave.net> scripsit:
* "Allen" <al***@sunwave.net> scripsit:
当使用FileInfo删除文件时,该文件仍保留在目录中(不会被删除)

Dim foo为New FileInfo(strFileToDelete)
尝试
foo.Delete()
Catch ex as IOException
''打开文件处理程序
End Catch

该文件存在且有效。路径存在且有效。除ARCHIVE外,没有设置文件
属性。我有权读取和写入目录。
没有抛出异常(ex = Nothing)但文件没有从
目录中删除。
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.




如果使用''System.IO.File.Delete(< filename>)''它是否有用?


-

Herfried K. Wagner [MVP]

< http://www.mvps.org/dotnet>



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

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>


我可以确认这不起作用,并且不会抛出任何异常。我

不知道为什么。这可能是个问题吗?


问候 - OHM

Herfried K. Wagner [MVP]写道:
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:
*艾伦 <人*** @ sunwave.net> scripsit:
* "Allen" <al***@sunwave.net> scripsit:
当使用FileInfo删除文件时,该文件仍保留在
目录中(未删除)

Dim foo为New FileInfo(strFileToDelete)
尝试
foo.Delete()
Catch ex as IOException
''打开文件处理程序
End Catch

该文件存在且有效。路径存在且有效。除ARCHIVE外,没有设置文件
属性。我有权阅读和写入目录。
没有异常被抛出(ex = Nothing)但文件没有从目录中删除
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.



如果使用''System.IO.File.Delete(< filename>)''它是否有效?



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




问候 - OHM#OneHandedMan { at} BTInternet {dot} com



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


这篇关于FileInfo.Delete无法删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆