【发布时间】:2014-12-04 00:04:52
【问题描述】:
所以我在这里有一个非常基本的问题......我们有一个应用程序,它依赖于一个存储设置的 xml 文件。有时,此文件已损坏,应用程序将在启动时失败。我想编写一个应用程序来查找 USED 文件和 BACKUP 文件。由于各种原因(10 年的更改等),应用程序使用的文件并不总是存储在同一位置,但它始终命名相同。
所以我的想法是我编写了一个简单的应用程序,它可以查找系统上文件的所有情况(通常是一个或两个 HDD),很明显哪个是使用的,哪个是备份的。
简单...但是在使用此代码进行迭代时
Private Sub Command1_Click(sender As System.Object, e As System.EventArgs) Handles Command1.Click
'variable to hold each hdd name eg: c:\
Dim hdd As String
Try
For Each drive As IO.DriveInfo In IO.DriveInfo.GetDrives
'asign the variable hdd a name for this run through
hdd = drive.Name
'search the hdd for the file user.config
For Each filename As String In IO.Directory.GetFiles(hdd, "user.config", IO.SearchOption.AllDirectories)
'variable to hold the path for each found file
Dim file As String = IO.Path.GetFullPath(filename)
'add each found file to the list
List1.Items.Add(file)
Next
Next
Catch ex As Exception
MsgBox(ex.ToString)
End Try
'iterate through each found drive
End Sub
我遇到的问题是访问被拒绝...
所以我认为我应该能够在对它进行任何操作之前检查权限?但是后来我想我实际上并没有尝试做任何事情,只是读对了吗?还是我错过了什么……
我尝试过更改权限,以管理员身份运行 VS2010 等,但这些都不起作用。
TIA
【问题讨论】: