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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:47:35+00:00 2026-06-10T03:47:35+00:00

I write a .bat to automate generating and compiling a cmake project. The batch

  • 0

I write a .bat to automate generating and compiling a cmake project. The batch file will

  1. optional rmdir build
  2. mkdir build if not exist
  3. cd build
  4. cmake .. generate a nmake project from upper folder
  5. nmake compile project

the source:

@ECHO OFF
set "OpenCV_LIB=C:\Program Files (x86)\OpenCV2.1"
echo !! OpenCV Library: [ %OpenCV_LIB% ]
IF NOT EXIST "%OpenCV_LIB%" (
    echo Can't find OpenCV Library, please change OpenCV_LIB setting
    GOTO END
)

if %PROCESSOR_ARCHITECTURE%==x86   set BUILD_ARCH=x86
if %PROCESSOR_ARCHITECTURE%==AMD64 set BUILD_ARCH=x86_amd64
if %PROCESSOR_ARCHITECTURE%==IA64  set BUILD_ARCH=x86_IPF
echo !! Target architecture [ %BUILD_ARCH% ]
call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" %BUILD_ARCH%

cd "sikuli-script"
set /p answer=Do you want to make clean first? (Y/N):
if %answer% == Y ( IF EXIST build rmdir /s /q build )
if %answer% == y ( IF EXIST build rmdir /s /q build )

IF NOT EXIST build mkdir build
cd build

IF NOT EXIST CMakeCache.txt ( cmake -G "NMake Makefiles" -D CMAKE_BUILD_TYPE=Release -D "OpenCV_DIR=%OpenCV_LIB%" .. )
nmake

:END
pause

After i run this .bat over and over, i notice that cd build failed sometimes, so i change my code to test it:

@ECHO ON
set /p answer=Do you want to make clean first? (Y/N):
if %answer% == Y ( IF EXIST build rmdir /s /q build )
if %answer% == y ( IF EXIST build rmdir /s /q build )
:DO_MKDIR_CD
IF NOT EXIST build mkdir build
cd build
if errorlevel 1 (
    pause
    GOTO DO_MKDIR_CD
)

It comes out the error happens every time choose to clean up build, even the build is at small size (e.g. after interrupted compiling, size 3.08 MB, 183 files, 67 dirs).

!! OpenCV Library: [ C:\Program Files (x86)\OpenCV2.1 ]
!! Target architecture [ x86_amd64 ]
Setting environment for using Microsoft Visual Studio 2010 x64 cross tools.

D:\repo\sikuli>cd "sikuli-script"

D:\repo\sikuli\sikuli-script>set /p answer=Do you want to make clean first? (Y/N):
Do you want to make clean first? (Y/N):y

D:\repo\sikuli\sikuli-script>if y == Y (IF EXIST build rmdir /s /q build  )

D:\repo\sikuli\sikuli-script>if y == y (IF EXIST build rmdir /s /q build  )

D:\repo\sikuli\sikuli-script>IF NOT EXIST build mkdir build

D:\repo\sikuli\sikuli-script>cd build
Access is denied.

D:\repo\sikuli\sikuli-script>if errorlevel 1 (
pause
 GOTO DO_MKDIR_CD
)
Press any key to continue . . .

So every time after remove and recreate build, the cd build fails, then cmake start messing up my source tree.

The error check and loop trying could fix this problem, but why is the file system not stable? or am i writing it in a wrong way?

  • 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-10T03:47:37+00:00Added an answer on June 10, 2026 at 3:47 am

    That build directory check:

    IF NOT EXIST build mkdir build
    

    Will create the directory if both directory and file named “build” are not exist.

    One way to check a directoy existence is:

    if exist build\nul echo directory exist
    

    If you want to make sure a directory exist use:

    if not exist build\nul mkdir build
    

    or better:

    if not exist build\nul (
      mkdir build
      if not exist build\nul (
        echo mkdir failed
        goto :eof
      )
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

H Hello, everyone. I intent to write a batch(umake.bat) file that does the following:
I am trying to write a .bat file to automate some shell commands. Most
I am trying to write a bat file for a network policy that will
I have two batch file bat1.bat and bat2.bat I need to write another batch
What should I write into the .bat file for it to find all files
I'd like to write a .bat file that can run same .exe file multiple
I need to write a command in a .bat file that recursively deletes all
I have a batch file named a.bat on a winserver2008 Desktop. That batch file
I am trying to write a batch file that exists in an arbitrary directory
I need to write a batch file to unzip files to their current folder

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.