C # file path operation summary

Source: Internet
Author: User

1. Obtain the path of the current file

1. System. Diagnostics. Process. GetCurrentProcess (). MainModule. FileName

Obtain the complete path of the module, including the file name.

2. System. Environment. CurrentDirectory

Obtain and set the fully qualified directory of the current directory from which the process starts.

3. System. IO. Directory. GetCurrentDirectory ()

Obtain the current working directory of the application. This is not necessarily the directory from which the Program starts. It may be stored in C: www. This function may return C: Documents and SettingsZYB, or C: Program FilesAdobe, sometimes it is not necessarily the same thing that is returned. This is the last operation directory of any application. For example, if you open the E: docmy.doc file in Word, then E is returned after executing this method: doc.

4. System. AppDomain. CurrentDomain. BaseDirectory

Obtain the base Directory of the program.

5. System. AppDomain. CurrentDomain. SetupInformation. ApplicationBase

Obtain and set the name of the directory containing the application.

6. System. Windows. Forms. Application. StartupPath

Obtain the path of the executable file that started the application. The effect is the same as that of 2 and 5. Only five strings are followed by one more "".

7. System. Windows. Forms. Application. ExecutablePath

Obtain the path and file name of the executable file that started the application. The effect is the same as that of 1.

Ii. Operating Environment Variables

The System. Environment. GetEnvironmentVariable () method can be used to conveniently obtain System Environment variables, such:

System. Environment. GetEnvironmentVariable ("windir") to obtain the path of the windows System directory.

The following are common values of environment variables:

System. Environment. GetEnvironmentVariable ("windir ");

System. Environment. GetEnvironmentVariable ("INCLUDE ");

System. Environment. GetEnvironmentVariable ("TMP ");

System. Environment. GetEnvironmentVariable ("TEMP ");

System. Environment. GetEnvironmentVariable ("Path ");

Finally, I posted the variable values obtained through the above operations. In advance, I wrote a WinForm program. The project file is stored in D: Visual Studio ProjectsMyApplicationLifeAssistant. The compiled file is located in D: visual Studio ProjectsMyApplicationLifeAssistantbinDebug. The final result is as follows:

1. System. Diagnostics. Process. GetCurrentProcess (). MainModule. FileName = D: Visual Studio ProjectsMyApplicationLifeAssistantbinDebugLifeAssistant.exe

2. System. Environment. CurrentDirectory = D: Visual Studio ProjectsMyApplicationLifeAssistantbinDebug

3. System. IO. Directory. GetCurrentDirectory () = D: Visual Studio ProjectsMyApplicationLifeAssistantbinDebug

4. System. AppDomain. CurrentDomain. BaseDirectory = D: Visual Studio ProjectsMyApplicationLifeAssistantbinDebug

5. System. AppDomain. CurrentDomain. SetupInformation. ApplicationBase = D: Visual Studio ProjectsMyApplicationLifeAssistantbinDebug

6. System. Windows. Forms. Application. StartupPath = D: Visual Studio ProjectsMyApplicationLifeAssistantbinDebug

7. System. Windows. Forms. Application. ExecutablePath = D: Visual Studio ProjectsMyApplicationLifeAssistantbinDebugLifeAssistant.exe

System. Environment. GetEnvironmentVariable ("windir") = C: WINDOWS

System. Environment. GetEnvironmentVariable ("INCLUDE") = C: Program FilesMicrosoft Visual Studio. NET 2003SDKv1. 1 include

System. Environment. GetEnvironmentVariable ("TMP") = C: required E ~ 1zhoufoxcnLOCALS ~ 1 Temp

System. Environment. GetEnvironmentVariable ("TEMP") = C: locale E ~ 1zhoufoxcnLOCALS ~ 1 Temp

System. environment. getEnvironmentVariable ("Path") = C: WINDOWSsystem32; C: WINDOWS; C: example; C: jdk1.5.0bin; C: MySQLServer5.0bin; C: Program example; C: Program FilesMicrosoft SQL Server80ToolsBINN

This article is from the "Zhou Gong's column" blog, please be sure to keep this source http://zhoufoxcn.blog.51cto.com/792419/167215

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.