-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy paththis.jsp
More file actions
112 lines (100 loc) · 4.43 KB
/
Copy paththis.jsp
File metadata and controls
112 lines (100 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.io.*,java.net.*,java.util.*" %>
<%
String spath = request.getParameter("delfil");
spath = java.net.URLDecoder.decode(spath, "UTF-8");
int meth = Integer.parseInt(request.getParameter("meth"));
if(meth==1){
if(spath.equals("0")){
clearAll(new File("/web_home/downloads"));
}else{
File path = new File(spath);
singleDelete(path);
}
}else if(meth==0){
if(start().length != 0){
out.println("<table border=\"1\">");
for(String se : start()){
se = se.replace("\\", "/"); //避开转义字符---反斜杠
//out.println("<tr><td class=\"private_td\"><a href='"+se.replace("/web_home","")+"'>"+se.replace("/web_home/downloads/","")+" </a></td><td style=\"white-space:nowrap;\" class=\"private_td\"><a href='javascript:void(0);' onclick='ajaxHttp(\"1\",\""+se+"\")'>Delete</a></td></tr>");
out.println("<tr><td class=\"private_td\"><a href='"+se.replace("/web_home","")+"'>"+se.replace("/web_home/downloads/","")+" </a></td><td style=\"white-space:nowrap;\" class=\"private_td\"><a href='javascript:void(0);' onclick='deleFile(\""+se+"\",this)'>Delete</a></td></tr>");
}
out.println("</table>");
}else{
out.println("<h4>NotFound File</h4>");
}
}else{
out.println("<h3>FREESPACE : "+Roots()+" MB</h3>");
};
%>
<% //查询文件列表%>
<%!
//String path = "/web_home/downloads";
File files = new File("/web_home/downloads");
String[] ss;
ArrayList<String> arr = new ArrayList();
public void parseFile(File file){
File[] f = file.listFiles();
if(f!=null){ //防止空指针错误
for(File ff : f){
if(ff.isDirectory()){
parseFile(ff);
}else{
if(ff.getName().substring(ff.getName().lastIndexOf(".") + 1).equals("mht") | ff.getName().substring(ff.getName().lastIndexOf(".") + 1).equals("chm") | ff.getName().substring(ff.getName().lastIndexOf(".") + 1).equals("url") | ff.getName().substring(ff.getName().lastIndexOf(".") + 1).equals("html") | ff.getName().substring(ff.getName().lastIndexOf(".") + 1).equals("txt")){
ff.delete();
}else{
arr.add(ff.toString());
}
}
}
}else{
return;
}
}
public String[] start(){
arr.clear(); //重置arraylist列表,避免无限打印
parseFile(files);
ss = arr.toArray(new String[arr.size()]);
return ss;
}
%>
<%!
boolean tt;
public void singleDelete(File fileName){
if(!fileName.exists()){
return;
};
if(fileName.isFile()){
tt = fileName.delete();
if(tt){
return;
}
}else{
System.out.print(fileName.toString());
return;
}
};
%>
<% //全部清理%>
<%!
public void clearAll(File file){
File[] files = file.listFiles();
if(files!=null){
for(File f : files){
if(f.isFile()){
f.delete();
}else if(f.isDirectory()){
clearAll(f);
f.delete();
}
}
}
}
%>
<% //查可用储存空间 %>
<%!
public long Roots(){
File sto = new File("/web_home/downloads");
return sto.getFreeSpace()/(long)1024/(long)1024;
}
%>