4 Replies Latest reply on Sep 8, 2008 8:42 PM by baftos

    Renaming directory

      Hi All

      I have a directory which I can access from windows file explorer using \\app\comm\LATEST. I am trying to change the directory name and I always get directory does not exist.

      Here is the code I use, can you please let me know what could be the problem.

      File oldDir = new File("\\app\\comm\\LATEST");
                 System.out.println(" Latest directory does not exist.");
                 return false;
             String CurTimeStamp = DateUtils.now().replace(" ", "_");
             System.out.println("New Dir Name is:"+CurTimeStamp);
             File newDir = new File(CurTimeStamp);
             boolean Rename = oldDir.renameTo(newDir);
                   System.out.println("File or directory does not rename successfully.");
                   return false;
                   System.out.println("File or directory rename is successfully.");
        • 1. Re: Renaming directory
          First, your address translates into "\\\\app\\comm\\LATEST"
          Second, what kind of directory is this? Looks more like a local network machine...
          • 2. Re: Renaming directory
            This is a directory on a local network machine..
            Can't we change directory name on a network machine?

            What would be the right format of giving the directory name, if we can?
            Please let me know
            • 3. Re: Renaming directory
              First of all, you won't be accessing another machine with File class, that's for the local machine.
              You'll have to use some library for that... Google it.
              • 4. Re: Renaming directory
                If you can do this renaming from a command line, I think you can do it in Java, although I heard some rumors that
                there may be problems with Universal Path Names. Anyway, try it from the command line and please post the
                relevant contents of the Command Prompt here (copy and paste), so we can convert it to Java.

                Edit: If I understand well, oldDir.exists() returns false. This is because a Universal Path Name starts with 2 backslashes, which translate to 4 in your string.

                Edited by: baftos on Sep 8, 2008 4:40 PM