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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:18:20+00:00 2026-06-13T10:18:20+00:00

I am trying to make a simple batch to search within a folder for

  • 0

I am trying to make a simple batch to search within a folder for a folder that contains a user-prompted name, and if the folder is found, it will ask if the folder should be copied to a pre-defined location. When I type the lines separately in cmd, they work fine, but when I try to save it in a batch file and run it, it somehow closes somewhere in the for do right after the SET, so I’m suspecting it has something to do with how my FOR is formatted in Notepad++?

:START
    set /p nw=Please enter the search string: 

    FOR /f "tokens=*" %%i IN ('dir /a:d-s-h /b ^| findstr /i /m "%nw%"') do (
        echo found %%i &&echo.
        set /p cflag=Would you like to copy this folder over? Press 'y' and enter: 
        if %cflag%==y xcopy "%%i" "%sci%" /e
    )

set /p rflag=Search for another folder? Press 'y' and enter: 
if %rflag%==y goto START

This is going to be run on XP.

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-06-13T10:18:22+00:00Added an answer on June 13, 2026 at 10:18 am

    It has nothing to do with notepad++, the keyword is delayed expansion.

    %cflag% will be expanded while the for block is parsed, before any of the lines in the block are executed.
    Therefore it is still empty and it expands to nothing.
    And then the if clause has an invalid syntax.

    But you can solve it with delayed expansion.
    Just put this to the beginning of your batch.

    Setlocal EnableDelayedExpansion
    

    And then expand your variable with

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

Sidebar

Related Questions

I'm trying to make a batch file that executes a simple command: shutdown -h
I am trying to make simple java code that will check if a table
I am trying to make a simple image rotator that will rotate through a
I'm trying to make a script that will make a copy of a folder
Im trying to make a simple app (just for learning sake) that will be
New to batch files, first try actually. Trying to make a simple batch file
im trying to make a simple search on my database from the index action
Trying to make simple jQuery function to create a scrollToTop button that fades in
I am trying to make simple app that allows one to compare image to
I'm trying to make simple animation that would repeat several times (or infinitely). It

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.