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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:15:49+00:00 2026-06-12T12:15:49+00:00

I want to make a batch file that will search for all files in

  • 0

I want to make a batch file that will search for all files in a directory that are .sln files and then display them as a list, so the user can select which one they want from the list and it will open that file. Not sure about how to store the file to make them into a list. This is what i have so far..

set TT_API_PATH=C:\dir
cd %TT_API_PATH%
dir /b /s *.sln 
set cmd=dir /b /s *.sln 
FOR /F %%i IN (' %cmd% ') DO SET X=%%i
  • 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-12T12:15:51+00:00Added an answer on June 12, 2026 at 12:15 pm

    EDIT: Replaced the unnecessary and dangerous call echo %%x] !choice[%%x]! command with echo %%x] !choice[%%x]!. Not even sure why I included it in the first place.

    NOTE:

    Ignore the lone : lines, for some reason all the blank lines in my code collapsed, and it was nessicary to put something on blank lines to keep the formatting. Sorry.

    @echo off
    setlocal enabledelayedexpansion
    set count=0
    
    :
    :: Read in files
    for %%x in (*.sln) do (
      set /a count=count+1
      set choice[!count!]=%%x
    )
    
    :
    echo.
    echo Select one:
    echo.
    
    :
    :: Print list of files
    for /l %%x in (1,1,!count!) do (
       echo %%x] !choice[%%x]!
    )
    echo.
    
    :
    :: Retrieve User input
    set /p select=? 
    echo.
    
    :
    :: Print out selected filename
    echo You chose !choice[%select%]!
    

    EDIT: Changed example to include subdirectories as requested.

    To meet your request for sln files found in subdirectories, I changed the for %%x in (*.sln), which returns only the sln files found in the current directory, to for /f %%x in ('dir /s /b *.sln') which executes the dir /s /b *.sln command in the current directory and returns the results.

    To make the output as clean and clear as possible, I also changed what was printed when listing the files from the entire path !choice[%%x]!, to the relative path starting from the current directory !choice[%%x]:%cd%\=! ( Which replaces the current path and directory (%cd%) plus a backslash (\) with nothing).

    @echo off
    setlocal enabledelayedexpansion
    set count=0
    
    :
    :: Read in files
    for /f %%x in ('dir /s /b *.sln') do (
        set /a count=count+1
        set choice[!count!]=%%x
    )
    
    :
    echo.
    echo Select one:
    echo.
    
    :
    :: Print list of files
    for /l %%x in (1,1,!count!) do (
         echo %%x] !choice[%%x]:%cd%\=!
    )
    echo.
    
    :
    :: Retrieve User input
    set /p select=? 
    echo.
    
    :
    :: Print out selected filename
    echo You chose !choice[%select%]!
    

    The above code displays only the relative path from the current directory to the files, but leaves the full path inside the variable choice[#].


    If you don’t want to deal with the entire path at all, you can add a single line to the for /f %%x... loop, and restore the echo line in the for /l %%x ... loop to that in the (edited) first example, so that the code looks like this (Explaining where the changes go takes just as long as showing the entire code, so):

    @echo off
    setlocal enabledelayedexpansion
    set count=0
    
    :
    :: Read in files
    for /f %%x in ('dir /s /b *.sln') do (
        set /a count=count+1
        set choice[!count!]=%%x
        for %%y in (!count!) do set "choice[%%y]=!choice[%%y]:%cd%\=!"
    )
    
    :
    echo.
    echo Select one:
    echo.
    
    :
    :: Print list of files
    for /l %%x in (1,1,!count!) do (
         echo  %%x] !choice[%%x]!
    )
    echo.
    
    :
    :: Retrieve User input
    set /p select=? 
    echo.
    
    :
    :: Print out selected filename
    echo You chose !choice[%select%]!
    

    Editing / restoring that echo statement is not strictly necessary, and does not change the output at all, but it’s good programming practice because it just recognizes the fact that the path of the current directory in the choice[#] variable was already removed when the filenames were originally read in. Changing it removes unnecessary complexity and removes possible unexpected results if the code is ever changed or adapted for some other use. If you leave the line alone, it will once again attempt to replace all instances of the current directory in the variable choice[#] with nothing. When it fails to replace anything it will simply leave the string unchanged.

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

Sidebar

Related Questions

I want to make a batch file that waits for a few minutes, then
I want to make a batch file that takes a user input in minutes,
I want to make a batch file, that would make me happy a long
My aim: Use Windows batch script to ensure that all files within given directory
I have a batch file that automates copying a bunch of files from one
I was wondering if theres a way to make a batch file that uses
I am traversing a HTML document using javascript DOM. I want make a list
I have a batch file that contains commands to restore a database using patches
I want to have a batch file(must be placed on desktop) which does the
Is it possible to make batch file for compiling the code in MS cobol

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.