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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:27:12+00:00 2026-06-02T03:27:12+00:00

not sure what’s the best (or better ) way to write a bat script

  • 0

not sure what’s the best (or better) way to write a bat script to take name input and search a directory to see whether it exists.

do I need to output the directory list to a file first before running a comparison?

and if it makes a difference, the directory is on a repository so for my purposes I’ll be using ‘svn list’, but I thought a nice general solution for everyone would be nice.

  • 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-02T03:27:14+00:00Added an answer on June 2, 2026 at 3:27 am

    If you are testing for a specific name within a directory, then you would generally do something like:

    if exist name (echo found it) else (echo not found)
    

    Or if the name is incomplete

    if exist *name* (echo found it) else (echo not found)
    

    If you are testing for a name anywhere within a directory tree, then I would use

    dir /s /a-d *name* >nul && (echo found it) || (echo not found)
    

    If you are issuing a command that generates lines of output and you want to test if a name exists within any one line, then Windows pipes generally work fine, as long as the size of the output is not huge and the 2nd half can keep up with the 1st half.

    yourCommand | find "name" >nul && (echo found it) || (echo not found)
    

    But pipes become inefficient if the 2nd half is slow compared to the 1st half, and a lot of data must be buffered. In that case it is definitely better to use a temp file instead of a pipe. I incorporate a random number into the temp file name to guard against possible collision of multiple processes using the same temp directory.

    set tempFile="%temp%\myTempFileBaseName%random%.txt"
    yourCommand >%tempFile%
    <%tempFile% find "name" >nul && (echo found it) || (echo not found)
    del %tempFile%
    

    I generally use pipes unless I know I have a performance issue.

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

Sidebar

Related Questions

Not sure the best way of phrasing this so bear with me. Within Codeigniter
Not sure of the best way to ask this question other than: I'm writing
Not sure why the plugin is behaving this way but whenever I refresh the
Not sure how to name correctly this question so feel free to edit if
Not sure how best to explain this, so bear with me... I'm writing an
Not sure how I would check to see if the value of a nodes
Not sure why last print is off? Please see comments for specific question john
Not sure if possible, but is there a way to have an application running
Not sure how else to ask this but, I want to search for a
Not sure if this counts as programming related, it's a tool that I use.

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.