我知道用ASP里的FSO组件能好快捷方便的实现此功能,但在JAVA中我不知道用什么样的方法好,
JSP里有jspSmartUpload组件可以实现,但现在也没得下载了,还有什么样不用组件功能能够实现的啊?
以下是通过FSO遍历实现的方法
<%@ Language=VBScript %>
<%
'遍历目录以及目录下文件的函数,
%>
<%
function bianli(path)
set fso=server.CreateObject("scripting.filesystemobject") on error resume next
set objFolder=fso.GetFolder(path)
set objSubFolders=objFolder.Subfolders
for each objSubFolder in objSubFolders
nowpath=path + "\" + objSubFolder.name
Response.Write nowpath set objFiles=objSubFolder.Files for each objFile in objFiles
Response.Write "<br>---"
Response.Write objFile.name
next
Response.Write "<p>"
bianli(nowpath)'递归
next
set objFolder=nothing
set objSubFolders=nothing
set fso=nothing
end function
%>
<%
bianli("d:") '遍历d:盘
%>
JSP里有jspSmartUpload组件可以实现,但现在也没得下载了,还有什么样不用组件功能能够实现的啊?
以下是通过FSO遍历实现的方法
<%@ Language=VBScript %>
<%
'遍历目录以及目录下文件的函数,
%>
<%
function bianli(path)
set fso=server.CreateObject("scripting.filesystemobject") on error resume next
set objFolder=fso.GetFolder(path)
set objSubFolders=objFolder.Subfolders
for each objSubFolder in objSubFolders
nowpath=path + "\" + objSubFolder.name
Response.Write nowpath set objFiles=objSubFolder.Files for each objFile in objFiles
Response.Write "<br>---"
Response.Write objFile.name
next
Response.Write "<p>"
bianli(nowpath)'递归
next
set objFolder=nothing
set objSubFolders=nothing
set fso=nothing
end function
%>
<%
bianli("d:") '遍历d:盘
%>
{
try
{
File s_file = new File( s_path.toString() );
if (!s_file.exists())
{
System.out.println( "s_file is not a directory." );
return;
}
File[] files = s_file.listFiles();
for (int i = 0; i < files.length; i++)
{
//System.out.println( files[i].getName() );
logger.info( i + "==" + files[i].getName() );
String fileName = files[i].getName();
/*******************************************************************************************************
* if directory,circulate
******************************************************************************************************/
if (files[i].isDirectory())
{
StringBuffer s_subPath = new StringBuffer( s_path.toString() );
s_subPath.append( System.getProperty( "file.separator" ) );
s_subPath.append( files[i].getName() );
deleteSrcPicture( s_subPath.toString() );
}
else if (files[i].isFile())
{
//处理你需要的逻辑
}
}
catch (Exception ex)
{
logger.info( ex );
}