VB.NET:GetFiles方法-“访问路径‘G:\System Volume Information’”被拒绝。”
这是我的代码,
Dim allFiles As FileInfo() =
tempDir.GetFiles("*.pdf", SearchOption.AllDirectories)
我用谷歌搜索发现我需要更改我的应用程序的权限 项目属性>查看UAC设置>并将级别更改为 level="requireAdministrator"
但它也不起作用。我发现了一些关于 FileIOPermission 类的内容,但不知道如何实现它。
==>详细代码。
Dim tempDir As New DirectoryInfo(path)
Dim FileDetails(4) As String
Dim iTem As ListViewItem
If (tempDir.Attributes <> FileAttributes.System) Then
Dim allFiles As FileInfo() = tempDir.GetFiles("*.pdf", SearchOption.AllDirectories)
Dim oneFIle As FileInfo
For Each oneFIle In allFiles
FileDetails(0) = oneFIle.Name()
FileDetails(1) = oneFIle.FullName()
FileDetails(2) = oneFIle.Length() / (1024 * 1024)
FileDetails(2) = FileDetails(2).Remove(5)
iTem = New ListViewItem(FileDetails)
ListView1.Items.Add(iTem)
Next
End If
Path 是一个包含所需路径的字符串,在本例中为 G:\
Here is my code,
Dim allFiles As FileInfo() =
tempDir.GetFiles("*.pdf", SearchOption.AllDirectories)
I've googled and found that I need to change the permissions of my app fromProject properties > View UAC Settings > and change level to level="requireAdministrator"
But its also not working. I found something about FileIOPermission
class, but dont know how to implement it.
==> Detailed code.
Dim tempDir As New DirectoryInfo(path)
Dim FileDetails(4) As String
Dim iTem As ListViewItem
If (tempDir.Attributes <> FileAttributes.System) Then
Dim allFiles As FileInfo() = tempDir.GetFiles("*.pdf", SearchOption.AllDirectories)
Dim oneFIle As FileInfo
For Each oneFIle In allFiles
FileDetails(0) = oneFIle.Name()
FileDetails(1) = oneFIle.FullName()
FileDetails(2) = oneFIle.Length() / (1024 * 1024)
FileDetails(2) = FileDetails(2).Remove(5)
iTem = New ListViewItem(FileDetails)
ListView1.Items.Add(iTem)
Next
End If
Path is a string that contains the path required, in this case G:\
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不会在此文件夹中找到 PDF 文件:
所以就这样忽略它。
当然,
GetFiles()
不允许您忽略文件/文件夹,因此您必须 PInvoke 进入 FindFirstFile 等。有效地进行搜索。You won't find PDF files in this folder:
So just ignore it.
Granted,
GetFiles()
does not allow you to ignore files/folders, so you'd have to PInvoke into FindFirstFile et al. to do searches effectively.好吧,我想我解决了这个问题,我只是迭代了每个文件夹,检查了它们的属性,然后添加到列表中..我认为它正在工作..请检查一下..
Ok, I think I solved the case, I just iterated each folder, checked their attributes and then added to the list.. I think it's working.. Plz check it a bit..
系统卷信息文件夹是受操作系统保护的文件夹。即使您可能拥有管理访问权限,您仍然无法访问它。您可以从资源管理器本身尝试一下。 (需要启用选项才能显示受保护的操作系统文件。)
System Volume Information Folder is a O/S protected folder. Even though you may have administrative access, you still will not be able to access it. You can try it from Explorer itself. (Need to enable option to show protected Operating System files.)