Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a directory with a bunch of folders and I want to create a text file for each folder containing this string: Visit How can I do this with windows cmd?

share|improve this question

closed as not constructive by John Gardeniers, Dave M, Khaled, Alex, Antoine Benkemoun Feb 5 '13 at 17:26

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

This is actually fairly simple to do given a short string like that:

for /d %M in (E:\somdir\*) do echo "yourstring" > E:\somdir\%M\stringfile.txt

The /d flag tells for to do 'directories in the path

%M stands in for the directories being iterated over.

(e:\somdir*) is the path to be iterated over.

Everything after the do is the command it executes, using %M for each item iterated over.

share|improve this answer

Afaik, simple cmd does not provide the same power as bash or power shell. The most easiest way working on severall platforms is by using a macro-like language, looping through the directories and put the textfile. I suggest to use AutoIT -

Its VERY WELL documentaded and has much effort with just a few lines of code. Check the following helps:

It should not take more then 10 lines of code to do what you want.

share|improve this answer

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