Enter your email address:

Delivered by FeedBurner


Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Finding created/modified time of files in a folder
12-19-2011, 05:50 PM (This post was last modified: 12-19-2011 05:52 PM by rajasri.)
Post: #1
Shocked Finding created/modified time of files in a folder
Today we are going to learn about how to retrieve the created time and date of all files in a folder.
This is useful when you want to track the session information of certain files or folders.Lets look the code below.

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.io.File, java.util.Date, java.util.Calendar" errorPage="" %>

Quote:<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<%
String dir_name = "C:\\foldername";
//String dir_name = "/"; This line will give u the windows drive's root folder.

File fold = new File(dir_name);

if(fold.exists())
{
String all_files[] = fold.list();
int no_of_files = all_files.length;

for(int i=0; i<no_of_files; i++)
{
File f = new File(dir_name + "\\" + all_files[i] );
String complete_file_name = f.getPath();
String file_name = f.getName();
long last_modified_ms = f.lastModified();
Date date = new Date(last_modified_ms);
Calendar cal_date = Calendar.getInstance();
cal_date.setTime(date);
String last_modified_date = cal_date.get(Calendar.MONTH) + "-" + cal_date.get(Calendar.DATE) +"-"+ cal_date.get(Calendar.YEAR);
String last_modified_time = cal_date.get(Calendar.HOUR) + ":" + cal_date.get(Calendar.MINUTE) +":"+ cal_date.get(Calendar.SECOND);
%>

<a href="<%=complete_file_name%>"> <%=file_name%> </a> <b>Last Modified by </b> <%=last_modified_date%> <b>at </b> <%=last_modified_time%>
<br>

<%

}//end of for

}//end of if
else
out.println("Folder does't exist");
%>
<body>
</body>
</html>


Try this example and do comment us.

Happy coding.
Find all posts by this user
Add Thank You Quote this message in a reply
Advertise here or at any positions around our site send a mail to info@walkinsforum.com
Post Reply 


[-]
Share/Bookmark (Show All)
Facebook Linkedin Technorati Twitter Digg MySpace Delicious

Possibly Related Threads...
Thread: Author Replies Views: Last Post
Lightbulb compare current time with database retrieved time in jsp rajasri 0 200 12-19-2011 05:17 PM
Last Post: rajasri
Video Display current time and date in your Jsp page rajasri 0 957 12-12-2011 11:56 PM
Last Post: rajasri
Bug Print current time using java in jsp page rajasri 0 619 12-12-2011 11:20 PM
Last Post: rajasri

Forum Jump:


User(s) browsing this thread: 1 Guest(s)