Home>

Get file name method:

Use system.io.path.getfilename and system.io.path.getfilenamewithoutextension (no extension)

Get file path method:

//Get the full path of the current process,Contains the file name (process name).
string str=this.gettype (). assembly.location;
result:x:\ xxx \ xxx \ xxx.exe //(The directory where the .exe file is located + .exe file name)
//Get the new process component and associate it with the full path of the main module of the currently active process,Contains the file name (process name).
string str=system.diagnostics.process.getcurrentprocess (). mainmodule.filename;
result:x:\ xxx \ xxx \ xxx.exe //(The directory where the .exe file is located + .exe file name)
//Get and set the fully qualified path of the current directory (that is, the directory from which the process was started).
string str=system.environment.currentdirectory;
result:x:\ xxx \ xxx //(The directory where the .exe file is located)
//Get the base directory of the current application domain of the current thread,It is used by the assembly conflict resolver to probe assemblies.
string str=system.appdomain.currentdomain.basedirectory;
result:x:\ xxx \ xxx \ //(The directory where the .exe file is located + "\")
//Get and set the name of the directory containing the application.
string str=system.appdomain.currentdomain.setupinformation.applicationbase;
result:x:\ xxx \ xxx \ //(The directory where the .exe file is located + "\")
//Get the path of the executable file that launched the application,Does not include the name of the executable.
string str=system.windows.forms.application.startuppath;
result:x:\ xxx \ xxx //(The directory where the .exe file is located)
//Get the path of the executable file that launched the application,Include the name of the executable.
string str=system.windows.forms.application.executablepath;
result:x:\ xxx \ xxx \ xxx.exe //(The directory where the .exe file is located + .exe file name)
//Get the current working directory of the application (unreliable).
string str=system.io.directory.getcurrentdirectory ();
result:x:\ xxx \ xxx //(The directory where the .exe file is located)
c
  • Previous Detailed interpretation of character-oriented input streams in Java programming
  • Next In-depth analysis of some applications oriented to byte streams in Java programming