Batch file same attribute to a folder + all sub folders

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
steve.marks59
Posts: 4
Joined: 12 Feb 2011 18:25

Batch file same attribute to a folder + all sub folders

#1 Post by steve.marks59 » 09 Mar 2011 02:17

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.

steve.marks59
Posts: 4
Joined: 12 Feb 2011 18:25

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

#2 Post by steve.marks59 » 09 Mar 2011 22:09

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.

Post Reply