Getting info - if a folder exist ignoring varible

I am making a batch file which tells if a folder exist. \..\ - Consider is path is constant on all computers. \..\CompanyName\- Now i can check if this folder exists. \..\Companyname\Productname version x.x.x - Now I cannot check if "product" exits because if i use if exist "%constantpath%\Productname version 1.2.3" (code block) condition will only return true if Whole Name Matchs. If Productname version is 1.2.4 it will return false.so that batch file is good as dead.When i tried set dest=Productname Version 1.2.3

set temp=%dest:~0,11% // which means "Productname"

if exist "%constantpath%\%temp% (code block) to see if only "Product name Exists it returns with error Syntax of command is incorrect. i think path is incorrect

Answers


so that batch file is good as dead.

There's life in the old dog yet.

if exist can not work with wildcards, but dir can:

dir /s "%constantpath%\Productname version 1.*" >nul && (
  echo yes 
) || (
  echo no
)

This example will check for version 1.x.x

"%constantpath%\Productname*" will check for any version (with or without the string version .... Adapt to your needs.

In case you need the complete name:

for /f "tokens=*" %%i in ('dir /s /b "%constantpath%\Productname version 1.*"` do set "fullname=%%i"

if exist accept wild cards so you can try:

if exist "%constantpath%\Productname version ?.?.?" (
  echo it exists
)

It also work with non normalized paths so you can use things like \..\


I'd highly recommend using powershell for this, i had to do something recently similar because i needed to run an installer that could be in a various location but the first portion would always remain the same. It would be as follows.

$BaseDir = "\..\CompanyName\"
$NameToFind = "ProductName"

$MyVariable = Get-ChildItem $BaseDir -Recurse | Where-Object { $_.PSIsContainer -and $_.Name -like ($NameToFind)}

$productVersion = $myvariable.FullName

Write-Host $productVersion

Need Your Help

Add captions to very basic jquery carousel

javascript jquery html css web

I've seen this very simple jquery styled carousel on another thread and think it would be ideal for a project I'm doing but wondering how it could be adapted to include captions on the images?

On moving to TDD with node and mongo

node.js mongodb tdd mocha mongoskin

I want to use mocha to add to my program feature by feature, test by test.