0

I have a batch script that doesnt seem to be placing specific information inside a varible. Here is what I am having issues with:

FOR /f "tokens=*" %%f IN ('DIR /B %~dp0%%y\%%m\*.*') DO (
               WUSA %~dp0%%y\%%m\%%f /quiet /norestart /log:%~dp0%LOGFILE%

We have a files in the specific %~dp0%%y\%%m directory that lists .exe and .msi files. We want the name of the file placed into %%f so we can then run it, however everytime I run the batch file it states that it "cannot find the path specified".

I verified that the %~dp0%%y\%%m is the correct directory and that the DIR /B %~dp0%%y\%%m\*.* seems to list the file names correctly but for some reason it will not feed into %%f ....

I have tried putting Echo %%f after the DO to see if anything was being placed inside but it does not list anything.

Is there any ideas on how to fix this or what is going wrong? Essentially we want it to run in a loop and install each .exe in the file one after the other.

2
  • I don't see it clear. Are you trying to read a set of files and each of this files include a list of exe/msi files? If this is correct, how are the files indicated inside the lists? else, are you iterating over the exe/msi files contained in a folder? Commented Apr 7, 2015 at 19:27
  • @MCND correct, there is a directory of files in which the updates are in....%%y is the folder name which are all named after years (e.g. 2011, 2012..) the %%m stands for the months so inside 2011 will be jan, feb, mar..etc..... inside each month are the .exe/.msi files... (E.g. 2011\mar\install.exe).... there are a multitude of .exe/.msi files in each folder so I want to have the batch file run each file so it can install and that is why we are using WUSA.. Does that make it more clear for you? Commented Apr 7, 2015 at 19:32

1 Answer 1

1

You can try with

for %%f in ("%~dp0%%y\%%m\*.*") do (
    echo Installing "%%~ff"
    WUSA "%%~ff" /quiet /norestart /log:"%~dp0%LOGFILE%"
)

Simply iterate over the indicated set of files (for /f is not needed) and instead of composing the full path to the file, retrieve the reference to it with full path (%%~ff)

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you so much! Probably a dumb question but how does it know to grab the next .exe that is in the file?
Does it just automatically go to the next line in the for loop?
@Technic1an, read it as: for each file in the set store the file reference in the replaceable parameter (%%f in this code) and call the code in the do clause

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.