Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6539863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:54:35+00:00 2026-05-25T10:54:35+00:00

I try to rename a whole directory programmatically. The directory is on a server

  • 0

I try to rename a whole directory programmatically. The directory is on a server that is mounted on the local file system. I’m trying it to do like this:

public static void main(String[] args) {
    File dir = new File("/Volumes/video/Serien/Scrubs/Season 1");
    System.out.println("Start renaming: " + dir);

    String[] files = dir.list();
    for (String file : files) {
        System.out.println("Old name: " + file);
        File renamedFile = new File(file);
        System.out.println(renamedFile.toString());
        boolean success = renamedFile.renameTo(new File("Test " + renamedFile.toString()));
        System.out.println("New name: "+ renamedFile.toString());
        System.out.println(success);
        break;
    }
}

I now that it tries only to rename the first one, but nevertheless it returns false and doesn’t rename.

So any hints why? I do not get any exceptions. I think it is because the server requires authentication?

Edit: Since renameTo() seems to be platform-dependent: I’m using Lion OSX

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:54:36+00:00Added an answer on May 25, 2026 at 10:54 am

    Try using a fullpath + the directory name when you are trying to rename for both old and renamed directory. I believe list() returns the directory name only without the fullpath. I had similar problem before and it worked when I did that. Hopefully that works for you as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
I have a file structure like this: 00000010 000000001.file1 000000001.file2 00000020 00000003.file1 00000003.file2 00000003.file3
Sometimes, I come across a property that, when I try to rename it using
I try to add an addons system to my Windows.Net application using Reflection; but
I try to write KSH script for processing a file consisting of name-value pairs,
I try to instantiate an instance of SPSite on the farm server in a
My target DB is MySQL, but lets try to look at this problem more
For example, if I have two files: file1: This is file 1 and file2:
I have correctly initialized YouTubeService. I can move/delete/rename playlist entries, but when I try
Ok, that title is going to be a little bit confusing. Let me try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.