Jay
Jay

Reputation: 1422

Windows script to perform operation on each file in directory

I'm an absolute beginner in Windows script and i'm required to do the following :(

for /f %%f in '..\dir\'
# Create a text file titled '\dir\filename.bat', containing " xxxx <filename> xxxx"

Once that's done i'd then run all the batch files created simultaneously

cd ..\dir
for /f %%f in * do
start cmd.exe /C '%%f.bat'

I'd really appreciate it if someone could tell me how to do the file creation part and also verify the rest of the code.

Upvotes: 0

Views: 296

Answers (1)

Ricky Payne
Ricky Payne

Reputation: 149

I'm not sure what your trying to do here...

If you want to make a file, you can just echo the line and append it ot a file (if the file does not exist, it will be created)... So for the st part of your question.

cd \dir
for /f %%f in ('dir /b') do (
    echo "xxxx %%f xxxx" >> %%f.bat
    echo "second line of file if required.." >> %%f.bat
    echo "repeat for as many lines as you need.." >> %%f.bat
)

Not sure why you would want to run all the files together either... a lot of tiles may well cause ssues if they all open at once...

It would be more help if you could explain exactly what you needed to do, so people could perhaps offer better ways of achieveing the end result.

Edit

I've changed the code above so that it will work (I've tested, and it does what I think you need it to).

Upvotes: 1

Related Questions