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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:40:48+00:00 2026-05-24T04:40:48+00:00

I have a small code wich can return the list of files under any

  • 0

I have a small code wich can return the list of files under any directory.

What I need to do is get the Directories and Files under the first given directory.

This is the code I’m using.

    File dir = new File("C:/myDocument/myFolder");

    String[] children = dir.list();
    if (children == null) {

    } else {
        for (int i=0; i<children.length; i++) {

            String filename = children[i];
            System.out.println(filename);
        }
    }

Another thing is when I select the path from Windows 7, I get this C:\myFolder\myFolder.
If I use this path in Java I get this error Invalide Escape sequence
Do I have to change it to C:/myDocument/myFolder to get it work.

Help.

Thanks

  • 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-24T04:40:48+00:00Added an answer on May 24, 2026 at 4:40 am

    Yes, forward slashes are fine. They get normalized to the OS-dependent separator.

    What the error tells you is that \m is an invalid escape sequence. Each backward slash tries to escape the following character. So if you need backward slashes in a string, use a double slash: "c:\\myDocuments\\myFolder"

    In order to get directories and files, you use .listFiles() and then file.isDirectory() to check if it’s a directory.

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

Sidebar

Related Questions

I have a small chunk of code I can't seem to get working. I
I have many small files containing code fragments, pseudo-code algorithms, classes, templates, SQL-samples, etc.,
I have a small html code base that produces a list of unique links,
I have a small code snippet that I'm trying to get to work in
Here i have written a small code...in this looping is not done..only first image
I have a small custom dialog in wich I have a ListView with id:list.
I have a small piece of code that produce PrimeFaces dropdown List p:selectOneMenu ,
I have this small code library that I'm considering releasing into Open Source. I
I have a small code block that should append text to the beg of
I have a small code base using Subsonic 2.1 in my project. I would

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.