In the earlier post on Powershell,I had shown how to simultaneously open all the files of similar extension type within a given folder.
This naturally leads us to the extension – if we can open all the files at same time,is there any way we can write to those files too all in one go?
The answer is a definite yes through the wonders of PowerShell.
For example purposes,I have 3 txt files named a1.txt,a2.txt and a3.txt all residing in one folder named texts in D: drive.So the full path is D:texts which is the same scenario as in earlier post.
Suppose I want to append some text to all of the above 3 files simultaneously,it becomes ridiculously simple to do so using PowerShell.
Open PowerShell.(Start > Run> powershell or simply type in powershell in search box within Start Menu).
Type : Add-Content d:texts*.txt “Welcome”
What this will do is get the command Add-Context to append text mentioned within the quotes (Welcome) in this case to all the .txt files specified in the particular folder.
Here is what is seen once the above command is run :
All the 3 text files have been updated with single word Welcome as mentioned in the command.
I am pretty sure one can come up with many ways to avoid tedious data processing on multiple files using the above command within PowerShell.