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

  • Home
  • SEARCH
  • 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 8293073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:42:21+00:00 2026-06-08T13:42:21+00:00

So I have been making a program in Java to organize all my files.

  • 0

So I have been making a program in Java to organize all my files. I am starting with movie files since that is what I have the most of, but I plan on being able to checkBox all file types eventually.

Anyway, I had renameTo working fine when moving all files to a new folder. Next step was trying to alphabetize the files. I got this working fine as well, but obviously I needed to be able to remove articles(i.e. “the”, “a”, “an”) in order to properly alphabetize. I was able to do this in my ArrayList pretty easily, and then decided to actually rename the files.

I did a renameTo in order to rename the file the same filename minus the articles. I used:

  File newb = new File(folder+""+filelist[i].getName().substring(4));
  if(filelist[i].renameTo(newb)){}
  else{
      System.out.println("FAILED");
  }

Where folder is obviously the folder location the file is in and it is a substring of the original string minus 4 characters at the beginning for the word “The_” or “The.”

It then attempts to rename the file from within the same folder to itself minus the substring.

The result of this code is the file disappearing and file size being listed as 0 when calling the length() of that file. The file is not findable in Windows Explorer, BUT there is no extra space on my HDD!

Now to the questions:

  1. What is wrong with this? Should I be putting a temp file into another folder or something?
  2. Is there a way to release the files from Windows so they are not forever clogging up space on my HDD?
  3. Anything else you need to know? Want to add?
  • 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-06-08T13:42:31+00:00Added an answer on June 8, 2026 at 1:42 pm

    I’m not sure what’s going on, but constructing file names by appending strings can cause problems. (In particular, if folder doesn’t end with the path separator character, you might find your moved files in the parent folder. That would explain why the files disappeared without freeing any disk space. So instead of renaming, say, C:\movies\The_Sting.avi to C:\movies\Sting.avi, it ended up as C:\moviesSting.avi.)

    Try this instead:

    File parent = filelist[i].getParentFile();
    
    String newName = filelist[i].getName().substring(4);
    if (!filelist[i].renameTo(new File(parent, newName)) {
        System.out.println("FAILED");
    }
    

    Obviously, if all the files in filelist are from the same folder, then you only have to assign to parent once (before you start looping).

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

Sidebar

Related Questions

I have been making a program that creates multiple CSV's from another source CSV
I have been tasked with making an existing Java program available via a web
I have been making a little program that needs to read a list of
I am making a game that needs a crosshair. I have been playing with
I have tried making a fiddle for this, but it's been too difficult to
I don't know what I have been done. I am making a program. If
I'm making a program in Java that reads in some stuff from a file
Possible Duplicate: Java, GUI builder or hand coding? I have been making GUI hand-coded
Good afternoon. I have been making a small openGL based app for android that
So I have been charged with the task of making all of the computers

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.