Hello everyone!
I have a code below to get a specific file from my computer into the vb.net application I am developing.
Is there anyone who knows how to change the path? What if I will try to put the application on a different computer? Or rather getting a music file from other folder? The Application.StartupPath doesn't work. :(

If System.IO.Directory.Exists("C:\Documents and Settings\Mitchikels\My Documents\AVDC\Downloaded Files") Then
            Dim myDir As New System.IO.DirectoryInfo("C:\Documents and Settings\Mitchikels\My Documents\AVDC\Downloaded Files")
            For Each myFile As System.IO.FileInfo In myDir.GetFiles("*.mp3")
                Dim lvwItem As ListViewItem = lvdownloaded.Items.Add(myFile.Name.ToString())
                lvwItem.SubItems.Add(myFile.Extension.ToString())
                length = ((myFile.Length.ToString / 1024) / 1024)
                length = Format(length, "0.00")
                lvwItem.SubItems.Add(length & " " & sizetext)

            Next
        End If

Recommended Answers

All 2 Replies

What path? This is the one you wrote, how do we know your path mate??!

I have changed the code a bit, to what I think its best:

'WRITE CORRECT PATH FILE HERE:
Dim filePath As String = "C:\\Documents and Settings\\Mitchikels\\My Documents\\AVDC\\Downloaded Files"
If System.IO.Directory.Exists(filePath) Then
	Dim myDir As New System.IO.DirectoryInfo(filePath)
	For Each myFile As System.IO.FileInfo In myDir.GetFiles("*.mp3")
		Dim lvwItem As New ListViewItem()
		lvwItem.Text(System.IO.Path.GetFileNameWithoutExtension(myFile.FullName))'1st column		
		lvwItem.SubItems.Add(myFile.Extension)'2nd column		
		length = ((myFile.Length \ 1024) \ 1024).ToString()'if this lenght variable is type of string!!		
		'BTW Check for Correction of the math formula!!!
		length = [String].Format("0:0.00", lenght)
		lvwItem.SubItems.Add(length & " " & sizetext)
	Next
End If

What path? This is the one you wrote, how do we know your path mate??!

I have changed the code a bit, to what I think its best:

'WRITE CORRECT PATH FILE HERE:
Dim filePath As String = "C:\\Documents and Settings\\Mitchikels\\My Documents\\AVDC\\Downloaded Files"
If System.IO.Directory.Exists(filePath) Then
	Dim myDir As New System.IO.DirectoryInfo(filePath)
	For Each myFile As System.IO.FileInfo In myDir.GetFiles("*.mp3")
		Dim lvwItem As New ListViewItem()
		lvwItem.Text(System.IO.Path.GetFileNameWithoutExtension(myFile.FullName))'1st column		
		lvwItem.SubItems.Add(myFile.Extension)'2nd column		
		length = ((myFile.Length \ 1024) \ 1024).ToString()'if this lenght variable is type of string!!		
		'BTW Check for Correction of the math formula!!!
		length = [String].Format("0:0.00", lenght)
		lvwItem.SubItems.Add(length & " " & sizetext)
	Next
End If


The file path is what I'm talking about. I wanted my application to run on other computers as well, so my file path should be of universal use. I don't know if you understand what I'm talking about. But thank you for your response. I'll be trying out the changes you've made on the codes. ^_^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.