help with accessing my docs in visual basics

hey so like the title states, i need help fixing my code. i'm not exactly sure why its not working, but if you can help me out i'd appreciate it very much. the bolded calls to the function throws errors that say they can't find the folder.


Imports System
Imports System.IO

Public Class frmMain
' This program uses the environment class and username property to attain the username.

Private Sub cmdRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRun.Click
Dim intDocumentsSize As Int64
Dim intDriveCapacity As Int64
Dim intFreeSpace As Int64
Dim intMusicSize As Int64
Dim intTotalUsage As Int64
Dim intVideoSize As Int64
Dim strd2 As DriveInfo = New DriveInfo("C:\")
Dim strDirectoryName As String
Dim strDriveCapacity As String
Dim strFreeSpace As String
Dim strTotalUsage As String
Dim strUsername As String = Environment.UserName

intDriveCapacity = strd2.TotalSize
intFreeSpace = strd2.AvailableFreeSpace
intTotalUsage = intDriveCapacity - intFreeSpace

strDriveCapacity = FormatNumber(intDriveCapacity, 0, , , TriState.True)
strFreeSpace = FormatNumber(intFreeSpace, 0, , , TriState.True)
strTotalUsage = FormatNumber(intTotalUsage, 0, , , TriState.True)

lblDriveCapacity.Text = strDriveCapacity
lblUsage.Text = strTotalUsage
lblAvailableSpace.Text = strFreeSpace

strDirectoryName = "C:\Users\" & strUsername & "\My Videos\"
'intVideoSize = get_folder_size(strDirectoryName)

strDirectoryName = "C:\Users\" & strUsername & "\My Documents\"
'intDocumentsSize = get_folder_size(strDirectoryName)

strDirectoryName = "C:\Users\" & strUsername & "\My Music\"
'intMusicSize = get_folder_size(strDirectoryName)

lblVideos.Text = FormatNumber(intVideoSize, 0, , , TriState.True)
lblDocuments.Text = FormatNumber(intDocumentsSize, 0, , , TriState.True)
lblMusic.Text = FormatNumber(intMusicSize, 0, , , TriState.True)

Me.Refresh()

End Sub

Private Function get_folder_size(ByVal pDirPath As String) As Int64

Dim lngDirSize As Int64
Dim objFileInfo As FileInfo
Dim objDir As DirectoryInfo
Dim objSubFolder As DirectoryInfo

objDir = New DirectoryInfo(pDirPath)

For Each objFileInfo In objDir.GetFiles()
lngDirSize += objFileInfo.Length
Next

For Each objSubFolder In objDir.GetDirectories()
lngDirSize += get_folder_size(objSubFolder.FullName)
Next

Return lngDirSize

End Function

End Class
closed account (j3Rz8vqX)
I haven't done vb in a long time.

What error are you getting?

Is it:
Class 'System.IO.FileInfo' cannot be indexed because it has no default property.

?
no the error message says

DirectoryNotFoundException was unhandled
Could not find a path of the part 'C:\Users\Manny\My Videos\'
closed account (j3Rz8vqX)
Sorry, I'm stomp on this one; VB is on my laptop and unfortunately I do not have it at the moment.

My only guess is the pathing is incorrect.

Possibly try:(Excluding the remaining '\', though it shouldn't make a difference)
C:\Users\Manny\My Videos

or
c:\\Users\\Manny\\My Videos

If that doesn't work, hopefully another person can enlighten us.
yea that didn't work but thanks for the help
so i figured out that the folders needed to be renamed to just documents, music, and videos. but now the program keeps giving me an error for the documents folder saying

UnauthorizedAccessException was unhandled
Access to path 'C:\Users\Home\Documents\Music\' is denied

don't know why its saying \Music when I'm only asking for the documents
closed account (j3Rz8vqX)
My assumption:

-You're getting the folder size: (the size of all the objects in that folder).

My assumed behavior: (If you're on windows)

-The executable was executed from a location that does not have administrative permission.

My assumed solution:

a) Move the file to c: or a scope that has administrative privilege.

b) Modify the executable to have administrative privilege, if running by executable or give project folder administrative privilege.

That's my guess at least...
Topic archived. No new replies allowed.