Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

How to create a bat file that will execute a single command on all files with a particular extension.

I look for something like this which is there is linux for windows batch files

command *.extension

or even a way to loop through the file with extension would do.

share|improve this question

1 Answer

up vote 1 down vote accepted

If your command changes the filename and uses the same extension then this solution has a bug, and some files are processed more than once. There are ways around that.

@echo off
for %%a in (*.ext) do (
echo "%%a"
)
share|improve this answer
 
@foxdrive what does %%a mean. Can you please explain –  C J Jun 9 at 4:35
1  
The for in do command uses a metavariable and I called it %%a. In the example above, each file that matches the *.ext filespec will be echoed in place of the %%a inside the double quotes. You could also use %%b and %%c and %%A and %%B and %%C etc and they are case sensitive. In other types of for in do loops you assign say %%a and then extra tokens are used in alphabetical ASCII order, which is why I use %%a and not %%? or %%# which you see some people using. When every file has been echo'ed then the loop above will finish. –  foxidrive Jun 9 at 9:06
 
thanks a lot. Its extremely difficult to understand when the linux pattern and windows pattern is so different –  C J Jun 9 at 11:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.