I need a batch files the launches all files in a given folder (in this case it is c:\macros\day).
I've tried the following, but it doesn't seem to do anything.
for /f %i in ('C:\macros\Day /b') DO command %i
I need a batch files the launches all files in a given folder (in this case it is c:\macros\day).
I've tried the following, but it doesn't seem to do anything.
for /f %i in ('C:\macros\Day /b') DO command %i
This works from my command line:
for /F "usebackq" %%i in (`dir /b C:\macros\Day\`) DO %%i
as does this:
for %%i in (C:\macros\Day\*) do %%i
You used the incorrect variant of for
. simply do (pun intended) for %%i in (c:\macros\Day\*) do %%i
Edit:
If you need to run a command
on all files: for %%i in (c:\macros\Day\*) do command %%i
You should use dir /b
to list all files, so it becomes
for /f %i in ('dir /b c:\macros\Day') do command %i
Also, make sure that you make variables inside batch files %%i rather than %i otherwise you get an error in the form "i was unexpected at this time."
Running all files in directory via batch file with appended text on each line
An alternative is posted above - leave off the trailing "/Z /U" if you wish.
This is how I could run all powershell files in same directory as the batch file
@ECHO OFF
SET PowerShellExe=%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe
for %%i in (*.ps1) do (
%PowerShellExe% -NoProfile -ExecutionPolicy Bypass -Command %cd%\%%i
)