Solved Execute command from windows batch script

Microsoft Outlook 2010 (full product)
November 6, 2014 at 19:15:46
Specs: Windows 7, 8 Gb
I have a file located on a share folder. I have to execute that file from the local PC. The name of the file changes every day, hence I should find the name first and then execute that .exe file.

Here is my Batch:

@echo off

set FILE=FOR /F %%a IN ('dir /s/b') DO (
set FILE=%%a

start %FILE%

The last line does not execute the file. Instead of listing the whole path with the file at the end it shows the content of 'for' loop.
actually I see %a at the end instead of 'real' file
Why is that?

See More: Execute command from windows batch script

Report •

November 7, 2014 at 02:11:55
✔ Best Answer
Assuming you are running your batch from a prompt that has the shared folder as its current directory and the .exe file is the last in the dir list, you have to code

@echo off
for /F %%a in ('dir /S /B *.exe') do set FILE=%%a
start "" "%FILE%"

Report •
Related Solutions

Ask Question