Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to copy a dummy text file into every subdirectory of a given directory on a network drive (Windows). Because we're looking at hundreds or thousands of subdirectories, I can't do this manually, but I can create a list of relevant directories. This list could be passed to a batch file or similar.

I'm guessing the batch file would have some sort of FOR loop that takes a line from the directory list as counter. For each iteration, the loop would just create an empty file in the directory indicated by the counter, but I lack coding skills to make the appropriate batch file.

How do I best approach this problem?

Update:

c:\help for includes an /R switch that seems useful:

FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters]
Walks the directory tree rooted at [drive:]path, executing the FOR statement in each directory of the tree. If no directory specification is specified after /R then the current directory is assumed. If set is just a single period (.) character then it will just enumerate the directory tree.

This seems straightforward, but I need to read a line from the directory list:

for %? in (.) do echo %? > dumy_file.txt


Details: My team has a shared network drive with thousands of subfolders filled with stale documentation and old working documents; it's a mess. The plan is to create a new tree structure elsewhere (done) that reflects our future file concept, and then either move or delete the files in the old tree structure. To track which subdirectories have already been "migrated" we thought it would be convenient to have a "to do" marker in the form of a dummy file that can be searched for.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Here's a one-liner that does what you want, using for /r as you suggest.

If you put it in a batch file, you must change %d to %%d in both places.

for /r %d in (dummyfilename.txt) do echo dummy content > "%d"
share|improve this answer
    
Thank you! I created a template file and ended up using this variant of your code: for /r K:\ %d in (todo.txt) do copy S:\template.txt "%d" –  Torben Gundtofte-Bruun Apr 19 '13 at 11:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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