1

How do I check if a bunch of files exist in my script? I want my script to perform some add the files if its not present or just ignore and proceed with the rest of the code. This is what I have writtes:

if not exist qapi/qapi*.h (
    @ECHO OFF
    CD %~dp0\..\..
    ECHO %CD%
    SET TOP_IOE_SW= %CD%
    ECHO %TOP_IOE_SW%
    SET BUILD_DIR=%TOP_IOE_SW%/build/ms

    icacls * /q /c /t /grant Users:F
    mkdir include\qapi
    xcopy /Y qapi_export\qapi*.h include\qapi
    xcopy /Y qapi\common\qapi*.h include\qapi
    xcopy /Y core\api\qapi*.h include\qapi
    xcopy /Y qapi\build include\build\
)   
else (
    call :next)


:next
 ////the rest of the code comes here///

When I run the script, it keeps prompting me to overwrite these files. How can I have this done without the prompt?

Thanks

zedfoxus
  • 35,121
  • 5
  • 64
  • 63
user3281103
  • 129
  • 12
  • The relative paths look inconsistent, I don't think you're testing the same directory that you're copying to. What does the directory structure look like, and what directory are you starting in? (Please edit that information into your question.) Also, I recommend using `robocopy` instead of `xcopy` in batch scripts. – Harry Johnston Oct 15 '15 at 22:32
  • You are not the first, who fell into the famous [_delayed expansion trap_](https://stackoverflow.com/a/30284028/3439404). Moreover (even if you use `!CD!` instead of `%CD%`), spaces around the `=` operator in `SET` command do matter (as well as trailing spaces); therefore, use e.g. `SET "TOP_IOE_SW=!CD!"` – JosefZ Jul 07 '19 at 12:48

0 Answers0