0

I want to know how to get files with a given dynamic path and not a specific path.

For example, most beginners like me would use the complete path to move files to other folder like:

    Dim path As String = "c:\temp\mine\MyTest.txt" 
    Dim path2 As String = "c:\temp2\mine\MyTest.txt"

But this time i want it to code the path like this:

    Dim path As String = "..\mine\MyTest.txt" 
    Dim path2 As String = "..\mine\MyTest.txt"

is this possible in vb.net?

please help me guys.. i really need to do it like this.. i already have the codes for the specific path..

tris
  • 39
  • 1
  • 10
  • 1
    It's unclear what you mean by dynamic path. It has to be relative to something, like the application executable, or one of the environmental folders. Where should `Dim path2 As String = "..\mine\MyTest.txt"` point to in your example? `c:\temp2`? We need a starting point. – LarsTech Jan 17 '15 at 18:50
  • You can use codepaths like the ones you want, but they would be **relative** to the folder where your program is running, or to wherever folder is the current/startup. Not sure if that's what you mean by "dynamic" ("relative") paths instead of "specific" ("absolute") paths, or we're misunderstanding you. – Josh Part Jan 17 '15 at 19:14
  • it's not on the same folder as where the application is.. for example, a dropbox folder in the taskbar in desktop.. how can i have it's path? – tris Jan 18 '15 at 15:17
  • 1
    See [How do I programmatically locate my Dropbox folder using C#?](http://stackoverflow.com/a/10401659/719186) – LarsTech Jan 18 '15 at 16:08

1 Answers1

0

As I can't commment on the OP.

You can use this, when the file is in the same folder as where the application is running from:

         Dim path as string = Application.StartupPath + "MyTest.txt"

EDIT1:

    Dim dir As New DirectoryInfo("D:\")
    For Each foundFile As FileInfo In dir.GetFiles("*.*", SearchOption.AllDirectories)
        If foundFile.Name.ToString = "filename" Then
            MsgBox(foundFile.FullName)
        End If

    Next foundFile
Stef Smits
  • 39
  • 2
  • It's better to use `Path.Combine()` when creating path strings. You don't know if StartupPath ends with a backslash or not. – LarsTech Jan 18 '15 at 14:29
  • it's not on the same folder as where the application is.. for example, a dropbox folder in the taskbar in desktop.. how can i have it's path? – tris Jan 18 '15 at 15:16
  • Then you need to search the enitere computer for the file. – Stef Smits Jan 18 '15 at 16:51