jsp顯示當前資料夾下檔案列表
需求:伺服器上有一個資料夾使用者可以訪問,如頁面:http://localhost/demo/data/index.jsp,使用者可以訪問這個頁面,用於讀取檔案列表,但是無法讀取當前頁面資料夾下其他內容,不知道檔名,檔名是可變的。
程式碼:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.io.*,java.util.*, javax.servlet.*"%> <html> <head> <title>遍歷檔案目錄</title> <style type="text/css"> ul { list-style: none; } li { float: left; margin-left: 20px; margin-top: 20px; } body { text-align: center; font-size: 15px; } a { font-size: 22px; } a:link, a:visited { color: #06C; text-decoration: none; } a:hover { color: #f00; } </style> <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery/jquery.js"></script> <script type="text/javascript"> $(function() { var name = $("#names").val(); $("#data").html(""); $("#data").append(name) }); </script> </head> <body> <%!StringBuffer result = new StringBuffer();%> <% String url = request.getRequestURL().toString(); if (url.endsWith("/")) { url = url.substring(0, url.length()); } url = url.substring(url.lastIndexOf("/") + 1); String path = request.getRealPath(url); File dir = new File(path + "/"); String[] fileNames = null; if (dir.exists()) { if (dir.isDirectory()) { fileNames = dir.list(); } else { fileNames = dir.getParentFile().list(); } } result = new StringBuffer(); for (String str : fileNames) { if (str != null) result.append("<li><a href='" + str + "'>" + str + "</a></li>"); } %> <div id="main"> <h1>檔案列表</h1> <input type="hidden" id="names" value="<%=result%>" /> <ul id="data"></ul> </div> </body> </html>
相關推薦
jsp顯示當前資料夾下檔案列表
需求:伺服器上有一個資料夾使用者可以訪問,如頁面:http://localhost/demo/data/index.jsp,使用者可以訪問這個頁面,用於讀取檔案列表,但是無法讀取當前頁面資料夾下其他內容,不知道檔名,檔名是可變的。程式碼:<%@ page languag
批處理 顯示指定資料夾下檔案的大小和時間
@echo off For /F "dolims=" %%i in ('dir %1 /b /a-d ') do ( for %%j in ("%1\%%i") do echo %%~nxj %
清除當前資料夾下.svn檔案的方法
原文地址 @echo on color 2f mode con: cols=80 lines=25 @REM @echo 正在清理SVN檔案,請稍候...... @rem 迴圈刪除當前目錄及子目錄下所有的SVN檔案 @rem for /r . %%
Python獲取當前資料夾下的目錄和檔案
Python獲取當前資料夾下的目錄和檔案 # !/usr/bin/env python # -*-coding:utf-8-*- """ Copyright(c)2018 file: sambaCenter.py author: date
Linux下統計當前資料夾下的檔案個數、目錄個數
1) 統計當前資料夾下檔案的個數 ls -l |grep “^-“|wc -l 2) 統計當前資料夾下目錄的個數 ls -l |grep “^d”|wc -l 3) 統計當前資料夾下檔案的個數,包括子資料夾裡的 ls -lR|grep “^-“|wc
計算當前資料夾下所有檔案的大小
import os temp1 = os.listdir('.') temp2 = [] for each in temp1: temp2.append((each,os.path.getsize(each))) temp3 = dict(temp
【轉】【Linux】Linux下統計當前資料夾下的檔案個數、目錄個數
【轉】【Linux】Linux下統計當前資料夾下的檔案個數、目錄個數 統計當前資料夾下檔案的個數,包括子資料夾裡的 ls -lR|grep "^-"|wc -l 統計資料夾下目錄的個數,包括子資料夾裡的 ls -lR|grep "^d"|wc -l 統計當前資料夾下檔案的個數
linux 壓縮當前資料夾下所有檔案
linux zip壓縮。壓縮當前資料夾下所有檔案,壓縮為a.zip。命令列的方法是怎樣。 zip -r fileName.zip 資料夾名 tar tar命令可以用來壓縮打包單檔案、多個檔案、單個目錄、多個目錄。 常用格式: 單個檔案壓縮打包 tar czvf my.tar file1 多
linux 打包當前資料夾下所有檔案
tar czvf test.tar.gz * #壓縮當前資料夾下非隱藏檔案的檔案 tar czvf test.tar.gz .[!.]* #壓縮當前資料夾下隱藏檔案排除兩個隱藏資
fso獲取資料夾下檔案個數和顯示檔名(無後綴)
感謝sayhito333提供給我這段程式碼,為表示感謝,不修改其宣傳性的函式名了,呵呵! <%path = "database/"sub sayhito333(path)dim fsodim objFolderdim objFilesdim objFiledi
Dos指令碼 給當前資料夾下指定的字尾檔案們重新命名(檔名追加制定內容)
先把指令碼放這裡了,直接copy成bat檔案就可以使用: echo off&setlocal enabledelayedexpansion cls pause set /p suffix=請輸入需要修改的檔案字尾: set /p testsuffix=請輸入檔名需
Java與Python統計資料夾及子資料夾下檔案個數
package dang; import java.io.File; /** * @ClassName: FileCount * @Description: TODO() * @author: dangjinhu * @date:
Linux 檢視某資料夾下檔案數量
轉至:www.xitongzhijia.net/xtjc/20150504/47340.html LInux find指令的使用: find命令檢視(推薦): 所有子目錄的數量: [[email protected] ~]# find pma -type d
Mapreduce如何獲取讀取資料夾下檔案的名字
需要注意的導包的時候導這兩個包 import
Ubuntu檢視資料夾下檔案的個數
Linux下統計當前資料夾下的檔案個數、目錄個數 檢視當前目錄下的檔案數量(不包含子目錄中的檔案) ls -l|grep "^-"| wc -l 檢視當前目錄下的檔案數量(包含子目錄中的檔案) 注意:R,代表子目錄 ls -lR|grep "^-"| wc -l 檢視當前目錄下的資料夾目錄個
Linux隨筆 - Linux統計某資料夾下檔案、資料夾的個數
統計某資料夾下檔案的個數 ls -l |grep "^-"|wc -l 統計某資料夾下目錄的個數 ls -l |grep "^d"|wc -l 統計資料夾下檔案的個數,包括子資料夾裡的 ls -lR|grep "^-"|wc -l 統計/i
Java/Android 獲取資料夾的檔案列表(file.listFiles())並按名稱排序,中文優先
排序規則 因為是中國人,習慣性看中文資料夾放前面比較順眼,所以在別人部落格(https://blog.csdn.net/da_caoyuan/article/details/56664673)的基礎上,加上了自己的排序規則。 預設排序規則是按照ASCII碼錶排序(http://asci
IO流的學習--資料夾下檔案的複製
package com.nick.IO; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import
VBA遍歷資料夾下檔案檔案實用原始碼
‘批量遍歷資料夾下某類檔案,並統計編號 Sub OpenAndClose() Dim MyFile As String Dim s As String Dim count As Integer MyFile = Dir("d:\data\" & "*.csv")
PHP遞迴和非遞迴遍歷資料夾下檔案
function readDirFiles($dir){ $files= []; $queue=[realpath($dir)]; $currentPath = current($queue); while($currentPath) {