1

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.

1 Answer 1

2

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"
1
  • 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" Apr 19, 2013 at 11:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .