> int count = 1; > while (!createNewFile(f) && count < 9999) { > count++;
Duh! Change it to "int count = 0;"... Not so sure on the second part. Regards, Daniel -----Original Message----- From: A mailing list for discussion about Sun Microsystem's Java Servlet API Technology. [mailto:[EMAIL PROTECTED] Behalf Of ianus: Damian Croft Sent: Wednesday, 11 June, 2003 4:24 PM To: [EMAIL PROTECTED] Subject: multipart requests I'm using comoreilly servlet and MultipartRequest to upload large numbers of copies of the same file to the server and as a result I need to index each uploaded file. I've rewritten the code in DefaultFileRenamePolicy to accommodate this but can't get it to work completely. It renames the second file by adding the index 0002 to the end of the filename, then 0003 to the third and so on. My problem is that I can't get it to add an index 0001 to the filename of the first file. My code looks like this. Does anyone have any ideas?? public class DefaultFileRenamePolicy implements FileRenamePolicy { private boolean createNewFile(File f) { try { return f.createNewFile(); } catch (IOException ignored) { return false; } } public File rename(File f) { String name = f.getName(); String body = null; String ext = null; int dot = name.lastIndexOf("."); if (dot != -1) { body = name.substring(0, dot); ext = name.substring(dot); // includes "." } else { body = name; ext = ""; } int count = 1; while (!createNewFile(f) && count < 9999) { count++; String c = new Integer(count).toString(); StringBuffer ct = new StringBuffer(c); ct.insert(0,"000"); String newName = body + ct + ext; f = new File(f.getParent(), newName); } return f; } } I have one other problem. I need to recover the size of the upload directory after the files have been uploaded. I've inserted these two lines of code into DemoRequestUploadServlet, File upDir = new File(dirName); out.println("Present size of Upload directory: " + upDir.length()); and put them right before the line out.println("FILES:"); But it obviously isn't working because it gives me the wrong value. My guess is that it is giving me the string length of the filenames in the folder (but I can't see why), so surely I am using the wrong method. Or have I put it in the wrong place? I've tried using the getSize() method, but i can't get it to compile without giving me all sorts of error messages. Has anyone got any ideas on how to solve this? Many thanks in advance. Damian ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html