# Batch file same attribute to a folder + all sub folders



## zappelectric19 (Aug 6, 2009)

I need a batch file to assign the same attribute to a folder and all its sub folders.
Can this be done using an argument or a "wildcard" instead of assigning the attribute to
each sub folder individually? I use XXCopy in my batch files.

Instead of having to do this:


```
attrib +r "D:\My Documents\Main Folder"
attrib +r "D:\My Documents\Main Folder\Sub Folder 1"
attrib +r "D:\My Documents\Main Folder\Sub Folder 2"
attrib +r "D:\My Documents\Main Folder\Sub Folder 2\Sub Folder A "
```
Thanks.


----------



## zappelectric19 (Aug 6, 2009)

I was given the answer below on another forum here:

http://www.theeldergeek.com/forum/index.php?showtopic=44616



> You can try using the /S and /D switches:
> EX:
> attrib +r "D:\My Documents\Main Folder\*.*" /S /D
> 
> ...


----------



## Squashman (Apr 4, 2003)

But that will also process the files within the folders. If you just want to do it on the folders you would need to run the DIR cmd inside a For Loop.


----------



## zappelectric19 (Aug 6, 2009)

Thank you Squashman. I would appreciate it if you could explain how to


> run the DIR cmd inside a For Loop


. I am an extreme novice in regards to writing scripts.

My purpose is to make an exact copy of a folder including the folder and sub folders disributable custom folder icons.
If the destination folder with the same name has a different custom icon I want it changed to be identical to the source. 
If the source folder has no icon but the destination folder does I want the destination folder to display no icon. 
After much trial and error the only combination of commands I found to accomplish this was the following:



> xxcopy "C:\FOLDER\" "D:\FOLDER\" /CLONE /YY /PB
> attrib +r "D:\FOLDER"
> attrib +r "D:\FOLDER\*.*" /S /D
> attrib -r "D:\FOLDER\*.*" /S


NOTE: Sometimes I include the " /IP" (If Present) switch in the xxcopy command line.

I realize this is setting the read only attribute for the folder, sub folders, and files and then clearing the read only 
attribute for all the files. This is the only combination I found to achieve my goal. It has worked 100% of the time.


----------

