Batch file same attributes to sub folders

March 9, 2011 at 00:13:37
Specs: Windows XP, 2.0 GHz, 512MB
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 "


See More: Batch file same attributes to sub folders

Report •

March 9, 2011 at 10:09:14
attrib +r "D:\My Documents\Main Folder\*.*" /s

Always try the /? to see what options the command has.

Report •

March 9, 2011 at 19:48:59
Thanks ace_omega, I really appreciate the quick reply to answer my question. I thought there must be a simple argument to do this. Thanks also for the "/?" tip, I will use that in the future.

Report •

March 9, 2011 at 20:01:36
I was given the answer below on another forum here:

You can try using the /S and /D switches:
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.

So I should use both "/S" and "/D" switches right?

Report •

Related Solutions

Ask Question