How to move directory ( with contents) to another directory.

Discussion in 'Java' started by mike, Mar 14, 2008.

  1. mike

    mike Guest

    I am trying to move a directory ( and it's contents to a new
    directory). I have tried the following:

    System.out.println(nonCCResource.getLocation().toString());
    tmpDir = new File (nonCCResource.getParent().getLocation().toString(),
    nonCCResource.getName()+".tmp");
    boolean success = tmpDir.mkdirs();
    File dir = new
    File(nonCCResource.getParent().getLocation().toString(),
    nonCCResource.getName());
    boolean success1 = dir.renameTo(tmpDir);

    When checking success1 it is false. And the success is true.

    Any ideas how I can do this.

    cheers,

    //mike
    mike, Mar 14, 2008
    #1
    1. Advertising

  2. On Mar 15, 4:55 am, mike <> wrote:
    ...
    > Any ideas how I can do this.


    My guess would be that Java (or the OS) will
    not allow us to rename a directory to the name
    of an existing directory.

    Post runnable code and I might check further.

    --
    Andrew T.
    PhySci.org
    Andrew Thompson, Mar 14, 2008
    #2
    1. Advertising

  3. mike

    Roedy Green Guest

    On Fri, 14 Mar 2008 10:55:19 -0700 (PDT), mike
    <> wrote, quoted or indirectly quoted
    someone who said :

    >I am trying to move a directory ( and it's contents to a new
    >directory). I have tried the following:


    You can't rename a directory to move it to a different drive. You
    must have permissions on it to rename it.

    To move it to a different drive, you have to create a new dir, copy
    the files over, and then delete the original files and directory.

    If you want help from others, simplify your code to use hard coded
    strings or at least do println of each of your files so people can
    what the net result of your calls is.
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Mar 15, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Don Adams
    Replies:
    1
    Views:
    580
    Martin Honnen
    Mar 5, 2004
  2. Matt MacDonald
    Replies:
    0
    Views:
    389
    Matt MacDonald
    Jan 30, 2008
  3. Eduardo78
    Replies:
    0
    Views:
    239
    Eduardo78
    Nov 3, 2005
  4. Wsebob
    Replies:
    0
    Views:
    770
    Wsebob
    Feb 18, 2010
  5. Andrew Tomazos
    Replies:
    2
    Views:
    590
    Nobody
    Dec 12, 2011
Loading...

Share This Page