当前位置: 首页 > 图文教程 > 网络编程 > PHP > php获得一个文件夹下所有文件的文件名

PHP
PHP新手总结的PHP基础知识
php实现gb2312和unicode间编码转换
用php语言实现数据库连接详细代码介绍
详细解析 PHP 向 MySQL 发送数据过程
利用PHP V5开发多任务应用程序
详细讲解PHP中缓存技术的应用
php escapeshellcmd多字节编码漏洞
《PHP设计模式介绍》导言
《PHP设计模式介绍》第一章 编程惯用法
《PHP设计模式介绍》第二章 值对象模式
《PHP设计模式介绍》第三章 工厂模式
《PHP设计模式介绍》第四章 单件模式
《PHP设计模式介绍》第五章 注册模式
《PHP设计模式介绍》第六章 伪对象模式
《PHP设计模式介绍》第七章 策略模式
《PHP设计模式介绍》第八章 迭代器模式
《PHP设计模式介绍》第九章 观测模式
《PHP设计模式介绍》第十章 规范模式
《PHP设计模式介绍》第十一章 代理模式
《PHP设计模式介绍》第十二章 装饰器模式

PHP 中的 php获得一个文件夹下所有文件的文件名


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 314 ::
收藏到网摘: n/a

以下为引用的内容:

php:

<?php
$dir = "/etc/php5/";

if (is_dir($dir))
{
if ($dh = opendir($dir))
{
       while (($file = readdir($dh)) !== false)
       {
         echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
       }
       closedir($dh);
}
}

ASP:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Dim thisPath,FSO,fileItem,allFolder
thisPath = Server.MapPath(Request.ServerVariables("SCRIPT_NAME")) '得到ASP文件的路径
Set FSO = createobject("scripting.filesystemobject")'创建FSO对像
Set allFolder = FSO.GetFile(thisPath).parentfolder.files '得到ASP所在目录的父级对像,它就包括了这个ASP和这个文件夹下的其它文件。thisPath当然可以自定义。

'下面是生成xml文件:

Response.write("<?xml version=""1.0"" encoding=""utf-8""?>")'开始输出XML
Response.ContentType = "text/XML"
Response.Write("<path>")
For Each fileItem In allFolder '遍历整个对像中的元素
   If lcase(right(fileItem.name,4))=".jpg" Then '如果后缀是JPG,这是可以判断后缀。
   Response.Write("<url>"+fileItem.name+"</url>")'就把它的文件名输出为XML的一个新节点
   End If
Next
Response.Write("</path>")
Response.End()
%> '这是从blueidea-flash里学来的。呵呵。记录一下,防备忘记。