【发布时间】:2013-09-27 23:29:20
【问题描述】:
我有一个小问题。在程序结束时,它应该删除一个文件夹。
为了拒绝删除包含某个单词的文件夹,我想检查一个字符串(directory.fullname.tostring)是否包含存储在字符串数组中的任何元素。 字符串数组包含说明异常词的字符串。
这就是我得到的结果,我知道解决方案与此处所述相反:
If Not stackarray.Contains(dir.FullName.ToString) Then
Try
dir.Delete()
sw.WriteLine("deleting directory " + dir.FullName, True)
deldir = deldir + 1
Catch e As Exception
'write to log
sw.WriteLine("cannot delete directory " + dir.ToString + "because there are still files in there", True)
numbererror = numbererror + 1
End Try
Else
sw.WriteLine("cannot delete directory " + dir.ToString + "because it is one of the exception directories", True)
End If
【问题讨论】:
-
I wanted to check if a string (the directory.fullname.tostring) contains any of the elements which are stored in a string array..比如什么? -
这些元素是文件夹路径。比如“D:\stuff_not_to_delete”。
-
您的代码没有按预期工作? ..哪一部分?
-
第一行没有按预期工作。我应该反过来工作。预期的方法是:程序应检查 directory.fullname 的字符串是否包含任何元素,如果包含,则不应执行任何操作,否则应尽可能删除文件夹。现在它检查数组是否包含 dir.fullname 字符串并且没有预期的效果......
-
我认为
If Not stackarray.Contains(dir.FullName) Then应该足够了..
标签: vb.net string compare contains arrays