none
BATCH - Result of dir into variable RRS feed

  • Question

  • I have to localize an EXE file into an entire tree of folders, with a cmd like this : dir myexe.exe /S/B

    And I want to store the resultant full path of the founded exe files in a variable, and then launch this exe with some parameters.

    I don't know how to store the result in string format into a variable.. Maybe it's also possible to directly make a 'cd' to the full path of the founded exe file ?

    Thanks in advance

    Wednesday, May 9, 2018 2:05 PM

Answers

  • Do not use cmd/batch anymore. Powershell is much more powerful and feature rich.

    dir myexe.exe /S/B  translates to:

    Get-ChildItem -Name myexe.exe -Recurse | Select-Object -Property FullName

    And if you like you simply assign the result to a variable and use later on for whatever you need.


    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    Wednesday, May 9, 2018 2:16 PM