Page 1 of 1

Batch file same attribute to a folder + all sub folders

Posted: 09 Mar 2011 02:17
by steve.marks59
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:

Code: Select all

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.

Re: Batch file same attribute to a folder + all sub folders

Posted: 09 Mar 2011 22:09
by steve.marks59
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

/S Processes matching files in the current folder
and all subfolders.
/D Processes folders as well.

Microsoft Windows XP [Version 5.1.2600]
© Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Wingman>attrib /?
Displays or changes file attributes.

ATTRIB [+R | -R] [+A | -A ] [+S | -S] [+H | -H] [drive:][path][filename]
[/S [/D]]

+ Sets an attribute.
- Clears an attribute.
R Read-only file attribute.
A Archive file attribute.
S System file attribute.
H Hidden file attribute.