Reputation: 23
I have a large number of existing files. I want to create new text files that include the name of the existing files plus some additional text and then names the file with a different extension based on the original file name. I can use command or powershell.
For example.
Current filenames
123.yuv
456.yuv
Content in new (separate) files
123.yuv Hello World123
456.yuv Hello World546
New filenames
123.avs
456.avs
What I've tried: I created this simple code that puts all the output into a single file. I can then go through some gyrations to create separate files. But it would be easier to just create the separate files straight away. I've researched but was not able to figure it out.
(for %i in (*.yuv) do @echo %i Hello world%i) > "%~ni.avs"
Upvotes: 0
Views: 207
Reputation: 34989
The following code should accomplish what you desire:
for %i in ("*.yuv") do > "%~ni.avs" echo/%~i Hello World%~ni
Since in your code you placed parentheses around the whole for
loop, the redirection >
happens outside of the loop context, hence the loop variable %~ni
is not available.
Upvotes: 2