Hi
Try this
Label3.Text = IO.Path.GetFileName(Application.StartupPath)
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I would like to print the current directory name without showing the full path. With current directory I meant the current directory of the VB application from which it's launched. For example; if I launch the application from D:\ParentDir\DynamicDir 3, I should get "DynamicDir 3" and not the D:\ParentDir
I have tried following but I am getting full path:
Label3.Text = AppDomain.CurrentDomain.BaseDirectory
or
Label3.Text = Directory.GetCurrentDirectory()
and same results with following as well:
Label3.Text = My.Application.Info.DirectoryPath
Hi
Try this
Label3.Text = IO.Path.GetFileName(Application.StartupPath)
Hello @~OSD~
If you want a solution that works for .NET Framework and/or .NET Framework Core consider
These don't work on .NET Core 5 but work on .NET Framework
Label3.Text = Path.GetFileName(Application.StartupPath)
Label3.Text = Path.GetFileName(AppDomain.CurrentDomain.BaseDirectory)
This works on both .NET Core 5 and .NET Framework
Label3.Text = New DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).Name
The reason why the first two fail on .NET Core is because both have a trailing backslash which is not present on on .NET Core so we would need to use
Label3.Text = Path.GetFileName(Application.StartupPath.TrimEnd("\"c))
Or
Label3.Text = Path.GetFileName(AppDomain.CurrentDomain.BaseDirectory.TrimEnd("\"c))