Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

reading and storing the folder and file structure

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


package com.purge;
import java.io.File;
import java.util.ArrayList;
import java.util.List;




public class purgedFileTree {
public static void main(String args[])
{
MailEngineDAO mdao=new MailEngineDAO();
File folder = new File("D:\\Test main");
List<File> list = new ArrayList<File>();
String requestId="WS00201";
getFiles(folder, list);
System.out.println("list.size = " + list.size());
for(int i = 0; i < list.size(); i++)
{
if(list.get(i).getName().contains(requestId)){
if(!list.get(i).isDirectory())
{
System.out.println("Rquest Id==>"+requestId+"Folder path==>"+list.get(i).getParentFile()+":Filename==>"+list.get(i).getName()+"Deleted date==>"+new java.util.Date());
mdao.insertPurgedFiles(requestId,list.get(i).getParentFile().toString(),list.get(i).getName()) ;
}
list.get(i).delete();
}
}
}
private static void getFiles(File folder, List<File> list)
{
folder.setReadOnly();
File[] files = folder.listFiles();
for(int j = 0; j < files.length; j++)
{
list.add(files[j]);
if(files[j].isDirectory())
getFiles(files[j], list);
}
}
}






-------------------------------------------------


public int insertPurgedFiles(String requestid,String filepath,String filename)
{
int result =-1;
String sql = "";
PreparedStatement stmt = null;
ResultSet rs = null;
Connection con=null;
try{

con = ItilDbutils.getConnection();
sql = "INSERT INTO purge_files(REQUEST_ID,FOLDER_PATH,FILE_NAME,DELETED_DATE,DELETED_BY,SCHEDULAR_TYPE)VALUES(?,?,?,SYSDATE,'PUGRE_SCHEDULAR','DAILY')";
stmt = con.prepareStatement(sql);
stmt.setString(1,requestid);
stmt.setString(2,filepath);
stmt.setString(3,filename);
result = stmt.executeUpdate();

} catch(Exception sqlEx)
{

}
finally
{
ItilDbutils.closeConnection(con,null,stmt,rs);
}
return result;
}


-------------------------------------------


CREATE
TABLE "CGMNT"."PURGE_FILES"
(
"REQUEST_ID" VARCHAR2(100 BYTE),
"FOLDER_PATH" VARCHAR2(200 BYTE),
"FILE_NAME" VARCHAR2(100 BYTE),
"DELETED_DATE" DATE,
"DELETED_BY" VARCHAR2(200 BYTE),
"SCHEDULAR_TYPE" VARCHAR2(200 BYTE)
)




-------------------------------------




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">;
<%@ page import="java.util.*"%>
<html>
<script>
var i=1;
var paddingleft=30;
function addchild(id)
{
var ids1='PManager'+id;
var ids2='MManager'+id;
var paddinglefter=paddingleft+10;
alert(ids1+ids2);
document.getElementById(ids1).style.display="block";
document.getElementById(ids2).style.display="none";
var imgid1='PManager'+i;
var imgid2='MManager'+i;
var divid='testdiv'+i;
alert(imgid1+imgid2+divid);
var data="<div id="+imgid1+" style='display:none;padding-left:"+paddingleft+"px'><image src=\"images/minus.gif\" onclick='hidechild("+i+")' /> sub"+i+"</div><div id="+imgid2+" style='display:block;padding-left:"+paddingleft+"px'><image src=\"images/plus.gif\" onclick='addchild("+i+")' />sub"+i+"</div> </td></tr><tr><td><div id="+divid+" style='padding-left:"+paddinglefter+"px'></div></td></tr>";
//alert(data);
document.getElementById("testdiv"+id).innerHTML=data;
i++;
paddingleft+10;
}
function hidechild(id)
{
var ids1='PManager'+id;
var ids2='MManager'+id;
document.getElementById(ids1).style.display="none";
document.getElementById(ids2).style.display="block";
document.getElementById("testdiv"+id).style.display="none";
}
</script>
<%


%>
<body>
<form>
<div>
<table id="test" border="0">
<tr>
<td> <div id="PManager0" style='display:none;padding-left:20px'><image src="images/minus.gif" onclick="hidechild('0')" title="adfasdfasd" />Manager</div>
<div id="MManager0" style='display:block;padding-left:20px'> <image src="images/plus.gif" onclick="addchild('0')" />Manager</div>
</td></tr><tr><td> <div id="testdiv0" style='padding-left:30px'>
</div></td></tr>

</tr>
</table>
</div>
</form>
</body>
</html>
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you have a question ?
 
nagaraju dameruppula
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Joanne Neal,
Im working on "deleting all the files and folders whose name matches with given string"
I want display all files deleted from the folders.
I also want to delete all the subfolders of matched folder irrespective of pattern matches.
the final deleted folder path, file name should be displayed as treeview.

I endup with this code any help is appricated.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

nagaraju dameruppula wrote:Im working on ...
I want ...
I also want ...

... any help is appricated.


You really need to tell us where you're stuck, or what doesn't do what you thought it would. See TellTheDetails (that's a link, click it). You also need to comply with Campbell's advice and post the code in tags: see UseCodeTags (that's a link, click it).
 
This is my favorite tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic