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 8141941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:40:29+00:00 2026-06-06T12:40:29+00:00

The folder I need to delete is one that is created from my program.

  • 0

The folder I need to delete is one that is created from my program. The directory is not the same on every pc so the folder code I am using is

userprofile+"\\Downloads\\Software_Tokens"

There will be files in, so I guess i need to recursively delete it. I looked at some samples for that here but it never accepts my path. The path works fine in the code as an environmental variable, because i added code for it

static String userprofile = System.getenv("USERPROFILE");

so can someone just show me the code with my path plugged please?

  • 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-06T12:40:31+00:00Added an answer on June 6, 2026 at 12:40 pm

    If you don’t want to use apache library ! You can do it recursively.

      String directory = userprofile + File.separator + "Downloads" + File.separator + "Software_Tokens";
      if (!directory.exists()) {
          System.out.println("Directory does not exist.");
          System.exit(0);
      } else {
          try {
              delete(directory);
          } catch (IOException e) {
              e.printStackTrace();
              System.exit(0);
          }
      }
      System.out.println("Done");
      }
      public static void delete(File file)
       throws IOException {
          if (file.isDirectory()) {
              //directory is empty, then delete it
              if (file.list().length == 0) {
                  file.delete();
                  System.out.println("Directory is deleted : " + file.getAbsolutePath());
              } else {
                  //list all the directory contents
                  String files[] = file.list();
                  for (String temp: files) {
                      //construct the file structure
                      File fileDelete = new File(file, temp);
    
                      //recursive delete
                      delete(fileDelete);
                  }
                  //check the directory again, if empty then delete it
                  if (file.list().length == 0) {
                      file.delete();
                      System.out.println("Directory is deleted : " + file.getAbsolutePath());
                  }
              }
          } else {
              //if file, then delete it
              file.delete();
              System.out.println("File is deleted : " + file.getAbsolutePath());
          }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a program that will need to delete a folder (and then
I need to delete a folder with contents using PHP. rmdir() and unlink() delete
Could any one clarify me that, when uninstalling I need to delete everything form
I need to delete a directory that contains read-only files. Which approach is better:
I need a function to delete all the csv files in a folder A,
I need to move a folder from a plugin to the main app/views. I
i need to see a folder (svn) from file system in eclipse (is there
I need a way to remove unused images from my filesystem, i.e. images that
I need to write a code in C# that will select a list of
A.) When i use code to delete lets say Image123.jpg in folder Pics and

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.