dir函数_PHP dir()函数与示例

一时失言乱红尘 2023-03-05 09:59 126阅读 0赞

dir函数

PHP dir()函数 (PHP dir() function)

dir() function is an instance of the directory class, it is used to read the directory, it includes handle and path properties – which can be used to get the resource id and path to the directory. Both handle and path have read(), rewind(), and close() methods.

dir()函数是目录类的实例,用于读取目录,它包括句柄和路径属性–可用于获取资源ID和目录的路径。 句柄和路径都具有read() , rewind()和close()方法。

Syntax:

句法:

  1. dir(directory,context);

Parameter(s):

参数:

  • directory – It is used to specify the path to the directory to be opened.

    directory –用于指定要打开的目录的路径。

  • context – It is an optional parameter; it defines the context (a set of options that can modify the behavior of the stream).

    上下文 –它是一个可选参数; 它定义了上下文(一组可以修改流行为的选项)。

Return value:

返回值:

On success – it returns an instance to the directory, on fail – it returns “FALSE”.

成功–将实例返回目录;失败–将返回“ FALSE”。

Example: PHP code to demonstrate example of dir() function

示例:PHP代码演示dir()函数的示例

  1. <?php
  2. //path to current working directory
  3. $cwd = dir(getcwd());
  4. echo "Directory handle: " . $cwd->handle . "<br>";
  5. echo "Current path: " . $cwd->path . "<br>";
  6. //reading & printing the filenames using dir()
  7. while (($file = $cwd->read()) !== false){
  8. echo "File: " . $file . "<br>";
  9. }
  10. //closing the dir instance
  11. $cwd->close();
  12. ?>

Output

输出量

  1. Directory handle: Resource id #5
  2. Current path: /home
  3. File: .
  4. File: ..
  5. File: main.php

Reference: PHP dir() function

参考: PHP dir()函数

翻译自: https://www.includehelp.com/php/dir-function-with-example.aspx

dir函数

发表评论

表情:
评论列表 (有 0 条评论,126人围观)

还没有评论,来说两句吧...

相关阅读

    相关 dir()函数

    dir()函数 Python中有非常多的模块,但是有的时候我们会忘记一个模块有哪些功能。这个时候,我们可以用dir()函数来查看一下指定模块的功能列表。

    相关 Python 内置函数 dir()

    在 Python 中,有大量的内置模块,模块中的定义(例如:变量、函数、类)众多,不可能全部都记住,这时 dir() 函数就非常有用了。 dir() 是一个内置函数,用于列

    相关 delete dir

    Linux删除目录命令rmdir 名称:rmdir 使用权限:于目前目录有适当权限的所有使用者 使用方式: rmdir \[-p\] dirName