IF Exists in Batch File

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

ash786

Thread Starter
Joined
Oct 19, 2009
Messages
6
Hi!

I have a exe file in the Folder call FChart 4.0.1. I would like to write the batch script to check if FChart.exe exists in the FChart 4.0.1 folder then copy it to specified folder. NOTE: the issue is that I would like to have it generic therefore I want to avoid 4.0.1 and only look for FChart folder and then file inside. I've written script but it doesnt work and its not generating any error as well

IF EXIST "VMFChart *\VMFChart.exe" XCOPY "VMFChart *\*" "%vmpath%" /E /F /G /H

Thanks in Advance :)
 
Joined
Aug 7, 2007
Messages
9,028
Is the file name FChart.exe or VMFChart.exe? The text says FChart.exe, the command says VMFChart.exe. Same with the folder name.

Easiest way is to try to switch to the FChart* folder. If that succeeds, you then check for the file and copy it.
If FChart 4.0.1 is a folder under the Program Files folder, this should work:
Code:
@Echo Off
PushD %ProgramFiles%
PushD FChart* 2>Nul
If Errorlevel 1 Goto _NotFound
If Exist FChart.exe XCOPY "FChart.exe" "%vmpath%" /E /F /G /H
Goto _Copied
:_NotFound
Echo FChartXXX folder not found in %CD%
PopD
Goto :EOF
:_Copied
Echo FChart.exe copied to %vmpath%
PopD
PopD
Note that if you have different versions (FChart 4.0.1 and FChart 4.0.2), it will switch to the the first one as listed in a Dir command that is sorted by name. Names with numbers aren't always listed in the same order as in Windows Explorer.

HTH

Jerry
 

ash786

Thread Starter
Joined
Oct 19, 2009
Messages
6
TheOutCast: Thank you for your input.

The file name is VMFChart and the folder name is VMFChart 4.0.1, there always be one folder call VMFChart 4.X.X in the release build, so the solution you have proposed should work.

thank you for your help
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Members online

Top