1

I want to create a dir (named with a varible Utilities._Name)located two levels from the exe file,

My exe file is in C:\SGEA\SGEA\bin How can I do it so I get C:\SGEA\theNewDir without using full path, just relative paths?

If Not System.IO.Directory.Exists(Utilities._Name) Then
   System.IO.Directory.CreateDirectory(Utilities._Name)
Else
   MessageBox.Show("There is already a dir named: " & Utilities._Name, "SGEA", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
4

1 回答 1

1

If you have the path to the exe file, you can use the System.IO.Path Class to navigate easily:

Dim folder = Path.GetDirectoryName(theExeFile)
Dim grandparent = Path.GetDirectoryName(Path.GetDirectoryName(folder)) ' Up two directories

Dim newFolder = Path.Combine(grandparent, "theNewDir") ' Use this to create the new folder name cleanly

Utilities._Name = newFolder
于 2013-01-02T20:17:56.920 回答