0

I want to combine 3 strings and get the complete file path. But when i check for the file existance, it is failing. Please suggest a way to do this

set "path=D:\Build" set "config=x86" set "type=Release" set "fileName=abc.dll" set "filePath=%path%\%config%\%type%\%fileName%" if exist filePath ( :copy file code) 

2 Answers 2

1

Path is system/environmental variable, so use it carefully.

The PATH is the system variable that your operating system uses to locate needed executables from the command line or Terminal window.

PFB working example for your query:

@echo off set "fpath=D:\Build" set "config=x86" set "type=Release" set "fileName=abc.dll" set "filePath=%fpath%\%config%\%type%\%fileName%" IF EXIST "%filePath%" ( ECHO YES ) ELSE ( ECHO NO ) 
Sign up to request clarification or add additional context in comments.

1 Comment

@ Rajesh, how your answer wil help to solve my problem
1

You forgot to expand the variable with the file path!

if exist %filePath% ( :copy file code) 

Otherwise you test for a file named "filePath". Also, if the file path may include spaces you should enclose it in quotes:

if exist "%filePath%" ( :copy file code) 

Finally, you should not modify path variable as Rajesh suggested (nor date, nor time, etc), but this is not the cause of your problem.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.