About define (' Discuz_root ', substr (DirName (__file__), 0,-7)); Understanding define (' Discuz_root ', substr (DirName (__file__), 0,-7)) ;Get site root directoryFor the above statement has not understood what is meant to check the relevant
Introduction to the use of _ dirname in Node. js, node. js _ dirname
Preface
This article mainly introduces the use of _ dirname in Node. js for your reference. Let's take a look at the details below:
The method is as follows:
Create a file
App.
In php, the complete path and FILE name of the current running FILE are _ FILE _. if it is used in the included FILE, the included FILE name is returned, this is a magic variable (a predefined constant). we can use dirname and basename to obtain the
The PHP dirname function returns the directory name dirname
(PHP 4, PHP 5)
DirName-Returns the component path of the directory name
Describe
String dirname (string $ path)
Given that a string contains the path of the file, the function returns the
Description of UseThe dirname command can take the directory portion of a given path (strip non-directory suffix from file name). This command is rarely used directly from the shell command line, and I typically use it in a shell script to get the
$ CD ' DirName $ ' and pwd%} display the current directory name${#var} to be replaced by the number of variable charactersSpecial variables$ current Shell's PID? Exit status of the previous command! PID of the previous work performed in the
For example, the current file is placed under (d: \ www \) and the file name is test. php.
The test code is as follows:
Copy codeThe Code is as follows: Echo _ FILE _; // obtain the absolute address of the current FILE. Result: D: \ www \ test.
? For example: The program root directory in: E:\wamp\www1. __file__ the absolute path to the current fileReturns E:\wamp\www\index.php if called in index.phpNow look at the directory structure of the program root directoryIf you call __file__ in
Usage of dirname () and _ FILE _ constants in php
$ Basedir = dirname (_ FILE __);
?>
If B. php is referenced by the. php file require or include in another directory. The content of the variable $
__FILE__: explanation: the full path and file name of the file. If used in the include file, the include filename is returned. Since PHP 4.0.2, __file__ always contains an absolute path, and the previous version sometimes contains a relative path.
1. Use _ FILE _ and dirname (_ FILE _) and basename (_ FILE:It is usually very effective to use dirname (_ FILE _) when configuring the FILE path, however, because the path of _ FILE _ is the complete path of the FILE where the current code is
Dirname, realpath ,__ FILE __, dirnamerealpath related to PHP paths
For example, the program root directory is in: E: \ wamp \ www.
1. _ FILE _ absolute path of the current FILE
If you call index. php, E: \ wamp \ www \ index. php is
Transferred from: http://blog.csdn.net/peter_cloud/article/details/9308333Copyright Notice: This article for Bo Master original article, without Bo Master permission not reproduced. Unless your original is considered cross-platform. In Linux
First, use the--HELP parameter to see it. basename command parameters are very small and easy to master.$ basename--helpUsage examples:$ basename/usr/bin/sort Output "sort".$ basename./include/stdio.h. H Output "stdio".To specify a path for basename,
For example, the current file is placed under (d: \ www \) and the file name is test. php.The test code is as follows:Copy codeThe Code is as follows:Echo _ FILE _; // obtain the absolute address of the current FILE. Result: D: \ www \ test. phpEcho
The dirname, realpath, and FILE related to the PHP path, for example, the program root directory is in: E: \ wamp \ www.
1. _ FILE _ absolute path of the current FILE
If you call index. php, E: \ wamp \ www \ index. php is returned.
Next,
For example, the current file is placed under (d: \ www \) and the file name is test. php.TestedCodeAs follows:
Echo _ file _; // obtain the absolute address of the current file. Result: D: \ www \ test. php
Echo dirname (_ file _); //
For example: The program root directory in: E:\wamp\www
1. __file__ the absolute path to the current file
Returns E:\wamp\www\index.php if called in index.php
Now look at the directory structure of the program root directory
If you call
Http://blog.sina.com.cn/s/blog_9d074aae01013ctk.htmlFirst, dirname directive1. Function: Remove the file name from the given file name containing the absolute path (part of the non-directory) and return the remaining path (part of the directory)2.
Assuming that the current file is stored under (d:\www\), the file name is test.php.Assuming that the current file is stored under (d:\www\), the file name is test.php.Copy the Code code as follows:
Note: dirname (__file__) takes the absolute
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.