我不知道如何解释这个问题,但我想问你们,如果没有" C:\"你们怎么称呼文件夹中的所有文件?目录,所以无论我在另一台计算机上移动我的项目,我都不必编辑项目中的路径目录即使可能吗?我使用的是visual basic 2008。
答案 0 :(得分:1)
我建议使用AppDomain.CurrentDomain.BaseDirectory
,此代码将返回当前应用程序所在的目录,假设您要获取应用程序所在文件夹中的所有目录,然后您将获得某些内容像这样。
Dim currentpath As String = AppDomain.CurrentDomain.BaseDirectory 'Get the directory where the application is located.
Dim Directories() As String = Directory.GetDirectories(currentpath) 'get all the directories what are in the current location of the application
'
Console.WriteLine("This application is located at:: {0}", currentpath)
'
If Directories.Length = 0 Then
Console.WriteLine("There aren't any folders found in the location of the application.")
Else
'
Console.WriteLine("The follow folder(s) are found.")
'
For Each folder In Directory.GetDirectories(currentpath)
Console.WriteLine(folder)
Next
'
End If
'
Console.ReadLine()
输出:
This application is located at :: C:Users\Kona\Desktop\
The follow folder(s) are found.
C:\Users\Kona\Desktop\C#
C:\Users\Kona\Desktop\VB
C:\Users\Kona\Desktop\Haskell
C:\Users\Kona\Desktop\Java
答案 1 :(得分:0)
您可以轻松使用:
Environment.CurrentDirectory
变量。 (使用.. \上一个目录...)