|
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
|
|||
|
|||
|
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> <% 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.
|
|||
Advertise here or at any positions around our site send a mail to info@walkinsforum.com
|
« Next Oldest | Next Newest »
|
![]() |
|||||||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|
| Possibly Related Threads... | |||||
| Thread: | Author | Replies | Views: | Last Post | |
| compare current time with database retrieved time in jsp | rajasri | 0 | 200 |
12-19-2011 05:17 PM Last Post: rajasri |
|
| Display current time and date in your Jsp page | rajasri | 0 | 957 |
12-12-2011 11:56 PM Last Post: rajasri |
|
| Print current time using java in jsp page | rajasri | 0 | 619 |
12-12-2011 11:20 PM Last Post: rajasri |
|
User(s) browsing this thread: 1 Guest(s)






![[-]](images/royal_red/collapse.gif)






