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 from
Project 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:\
You won't find PDF files in this folder:
The
System Volume Information
folder is a hidden system folder that the System Restore tool uses to store its information and restore points. (MSDN)
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.