Monday, September 22, 2014

windows 7 - Write a dummy file into every subdirectory?


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.


Answer



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"

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...