aspose file tools*
The moose likes JSP and the fly likes renameTo() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "renameTo()" Watch "renameTo()" New topic
Author

renameTo()

Tex Abrey
Greenhorn

Joined: Oct 04, 2002
Posts: 24
Does anyone have an example as to how to use the renameTo() I can't find a good example that explains at all whats going on, on the net I want to move a file from one directory to another
Thanks
Tex
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12785
    
    5
Seems to me the documentation in the JavaDocs for java.io.File is pretty clear. In a server situation you may run into security restrictions that prevent arbitrary renameTo.
What exactly have you tried?
Bill
Tex Abrey
Greenhorn

Joined: Oct 04, 2002
Posts: 24
This is the code I am using
<%-- java include files --%>
<%@ page import="java.io.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.lang.Object" %>
<%@ page import="java.lang.System" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.*" %>
<%@ page import="java.util.StringTokenizer" %>
<%
//local directories
String dirURL= "/inet/docroot/Newsclippings/upload/.";
String absDIR= "/inet/docroot/Newsclippings/clippings/";
//collecting information from the clipping directory given above
File path = new File(dirURL);
//array for clipping directory contents
String[] list = path.list();
//starts going through the list of pdf files, searching for those that match the search criteria
for(int i = 0; i < list.length; i++) {
String pdfName = list[list.length - 1 - i];
String year = pdfName.substring(0,2) + "/";
String mon = pdfName.substring(3,5) + "/";
File old = new File(dirURL + pdfName);
File moved = new File(absDIR + year + mon + pdfName);
out.println(moved);

try{
boolean flag = false;
flag = old.renameTo(moved);
out.println(flag);
}
catch(Exception e) {
System.out.println(e);
}
}
%>
Tex Abrey
Greenhorn

Joined: Oct 04, 2002
Posts: 24
This is the out put i get
/inet/docroot/dabrey/Newsclippings/clippings/02/01/02-01-11_R01.pdf false
and the folder i am moving the file to has read/write/execute abilities
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: renameTo()