如何检查列表框项是否存在目录 [英] how to check if directories exists against listbox items
问题描述
大家好,
我想知道是否有人可以提供帮助.我有一个带有2个列表框的表单,允许用户输入目录路径,然后将其填充到listbox1中.我在表单上有一个按钮,希望能够按该按钮在列表框项目中进行循环操作,并检查目录是否存在.
我以为是这样的:
Hi All,
i was wondering if anyone could assist. i have a form with 2 listbox, that allows user to enter in a directory path that is then populated in to the listbox1. I have a button on the form that i want to be able to press which cycle through the listbox items and checks if the directory exists.
i was thinking it would be something along the lines of :
For Each something In listbox1
if system.io.file.exist(somethinghere2) = false then
'in second listbox display missing directory
listbox2.item.add("does not exist " & somethinghere2)
else
'if the directory does exist
'do nothing
end if
Next
这是出于帮助我完成工作的目的,因此,我不必手动检查用户是否删除了过分的目录....我不是一个程序员,但是任何帮助都是很棒的.
this is for purpose to help me with my job, so i dont have to manually check if users have deleted directories overnite.... im not much of a programmer but any help would be great.
推荐答案
如果要检查目录是否存在,应使用
System.IO.Directory.Exists()
函数,如果目录存在,则返回True
,否则返回False
.
如果要检查文件是否存在,则应使用
System.IO.File.Exists()
功能.
如果要遍历目录中的所有文件,则应使用
System.IO.Directory.GetFiles(string path)
查看有关System.IO.Directory的Microsoft文档
If you''re going to check if a directory exists, you should use
System.IO.Directory.Exists()
function which returnsTrue
if the directory exists andFalse
otherwise.
If you''re going to check if a file exists, you should use
System.IO.File.Exists()
function.
If you want to iterate through all files in a directory, you should use
System.IO.Directory.GetFiles(string path)
Check Microsoft''s documentation on System.IO.Directory
有关检查目录是否存在的简单解决方案,请尝试以下简单代码
For a simple solution to check if directory is exist just try this simple code
If Dir("yourdirectory") = "" Then
'' does not exist
End If
这篇关于如何检查列表框项是否存在目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!