Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a directory with a bunch of folders and I want to create a text file for each folder containing this string: Visit http://www.example.com. 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.

2 Answers 2

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 - http://www.autoitscript.com/site/autoit/

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

http://www.autoitscript.com/autoit3/docs/functions/FileCopy.htm

http://dailycupoftech.com/folder-recursion-in-autoit/

http://www.autoitscript.com/autoit3/docs/functions.htm

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.