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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:22:16+00:00 2026-05-23T08:22:16+00:00

I tried to list all files and directories on a directory by using this

  • 0

I tried to list all files and directories on a directory by using this format

dir1:::dir2:::file1:::file2:::

To achieve this, I wrote a batch script. Take a look at it :

    @echo off
    SETLOCAL ENABLEDELAYEDEXPANSION
    SET M=
    FOR %%d IN ('dir /B') DO SET M=!M!%%d:::
    ECHO %M%

Well, it works for directories/files that doesn’t contain spaces, but for those that contained it, it will show just the first word.
For example, suppose the files are “Blue hills.jpg” and “Sunset.jpg”.

The expected result is of course

Blue hills.jpg:::Sunset.jpg:::

But what appears instead is

Blue:::Sunset.jpg

FYI, I use WinXP. *Is that matter? I’ve tried to put quotes in “%%d” but it doesn’t work. How can I fix this?
Thanks for the help! And sorry for my bad english, I really have to improve it..

  • 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-23T08:22:16+00:00Added an answer on May 23, 2026 at 8:22 am

    You need to run your for loop for file names containing any text (spaces included) "tokens=*". The /f switch is to search for text (filename text).

    @echo off
    SETLOCAL ENABLEDELAYEDEXPANSION
    SET M=
    FOR /f "tokens=*" %%d IN ('dir /B') DO SET M=!M!%%d:::
    
    ECHO %M%
    

    Works for files and directories with spaces.

    If you use tokens=1 then you get the first word of each file name (using a space as separator). So you would see

    Blue:::Sunset.jpg:::
    

    If you use tokens=2 then you get the second word:

    hills.jpg:::
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to write a script to list all files in directories and subdirectories
I tried to recursively get all files and folder list.But I can only get
How do I list all programs installed on my computer? I've tried using the
I'm trying to make a script to list all directories, subdirectories, and files in
In a directory, I have a bunch of files like file1.tex, file1.pdf, file2.tex, file2.pdf
I want to get a list of all the files in a directory, like
I'm exploring python and tried to sort all files from a directory by last
I would like to list all files recursively in a directory. I currently have
i have tried many samples on the net to list all files in system
I wanted to list all the files under a directory which is on public

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.