This article is a mirror article of machine translation, please click here to jump to the original article.

View: 18440|Reply: 0

[Source] Difference between Directory.GetCurrentDirectory and Application.StartupPath

[Copy link]
Posted on 12/8/2016 11:06:32 AM | | |

The System.IO.Directory.GetCurrentDirectory() method is used to obtain the current working directory of the application.
System.Windows.Forms.Application.StartupPath gets the path to the application's executable, without the file name

The StartupPath executable is pinned and can be used for targeting
GetCurrentDirectory is not necessarily the directory where the executable file is located, depending on where it is launched

If there are two programs C:/A/a.exe and C:/B/b.exe
When starting b.exe in a.exe, System.Diagnostics.Process.Start(@"C:/B/b.exe")
In this case, the Directory.GetCurrentDirectory() method in b.exe returns a value of "C:/A" and an Application.StartupPath value of "C:/B"
If you start b.exe directly in C:/B/, both values will be the same, both "C:/B"

This is the difference between Directory.GetCurrentDirectory and Application.StartupPath

The two meanings are different.
Application.StartupPath is the startup directory of the program, which will not change after the program runs.

Directory.GetCurrentDirectory() is the "current directory" and can be changed while the program is running

Directory.SetCurrentDirectory() to change .

The default value of Directory.GetCurrentDirectory() is the same as that of Application.StartupPath().




Previous:lock Why can only lock the reference but not the value type
Next:Detailed explanation of several ways to solve the problem of a C# program that only allows one instance to run
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com