Hi everyone!
I've never worked with batch files before, but just found out I need it for the project I'm working on...
I've got a stack of files: temp0000.000, temp0000.001,... temp0000.364. Now, I want to perform the same operation on all of these files. Is there an easy way to do this? (e.g. with the for function)?
I know what the operation syntax should be btw, this is just about the way to do it for ALL of the files.
- Of course I tried reading some of the stuff online but I couldn't really figure it out
For loop: operation on a stack of files [newbie]
Moderator: DosItHelp
Which operation you need? Some operations may use the masks ? and * for manipulate with multiple files.
To manipulate files one by one, you can use command FOR
...or M$ util FORFILES.EXE
To manipulate files one by one, you can use command FOR
Code: Select all
for %%a in (temp0000.*) do echo Do something with "%%a"
...or M$ util FORFILES.EXE
If you should want to do more than one DOS command for each file then something like :-
Within the () brackets you can do extra tests upon each %%a item,
and do things such as copy all *.exe to a flash drive, type all *.txt files, and delete all *.tmp files.
Suggestion - for any dangerous operation such as DEL, use DIR %%a in your first attempt, and only replace DIR with DEL when you are satisfied that it will not accidentally select and damage files you need.
Alan
Code: Select all
@echo off
for %%a in (C:\Your_Path\*.*) do (
dir %%a | find "/"
attrib %%a
)
pause
Within the () brackets you can do extra tests upon each %%a item,
and do things such as copy all *.exe to a flash drive, type all *.txt files, and delete all *.tmp files.
Suggestion - for any dangerous operation such as DEL, use DIR %%a in your first attempt, and only replace DIR with DEL when you are satisfied that it will not accidentally select and damage files you need.
Alan