Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch file to execute all files in a folder

Tags:

batch-file

dos

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
like image 201
sifuhall Avatar asked Feb 12 '12 16:02

sifuhall


People also ask

How do I run a batch file in a folder?

Open Start. Search for Command Prompt, right-click the top result, and select the Run as administrator option. Type the following command to run a Windows 10 batch file and press Enter: C:\PATH\TO\FOLDER\BATCH-NAME. bat.

What is %% f in batch file?

%%parameter A replaceable parameter: in a batch file use %%G (on the command line %G) FOR /F processing of a text file consists of reading the file, one line of text at a time and then breaking the line up into individual items of data called 'tokens'.

What does %% mean in batch?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.


2 Answers

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
like image 108
Adam Liss Avatar answered Oct 21 '22 12:10

Adam Liss


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

like image 21
wmz Avatar answered Oct 21 '22 14:10

wmz