• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 895
  • Last Modified:

Batch or DOS command to Attrib +S (Add System Attribute) to All Folders

I want an easy command to the run the Attrib +S "Directory Name" command on a all of the folders within the current directory. I figure piping output of dir /AD /B is a good start, since it lists all the folder names in the current directory.

However, I guess my problem is I can't figure out how to append quotes in what I'm doing right now now (see code below). Any ideas how to fix?

(I'm only looking for a code solution. No interface or 3rd party tool solutions, please.)
attrib +s | dir /AD /B

Open in new window

0
travisjbennett
Asked:
travisjbennett
  • 7
  • 4
  • 2
2 Solutions
 
knightEknightCommented:
for /f  %D  in ('dir/ad/b') do atttrib +s "%D"
0
 
knightEknightCommented:
oops, forgot the delims:

for /f "delims="  %D  in ('dir/ad/b') do attrib +s "%D"
0
 
Christopher McKayCommented:
Have you tried

For /f %i in ('dir /ad /b') do attrib +s %i






Hope this helps!

:o)

Bartender_1
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
knightEknightCommented:
The above will work if you run it directly from a command prompt in the parent directory of the subs.
If you want to use this in a .BAT file, you must double-up the percents like this:

for /f "delims="  %%D  in ('dir/ad/b') do attrib +s "%%D"
0
 
Christopher McKayCommented:
I'm slow today.

Hello KeK.

Time for me to find some more coffee. Sorry to duplicate your answer.
0
 
knightEknightCommented:
no worries!  you know that I am fond of this saying:

Great minds think alike -- ... and so do ours!  :p
0
 
travisjbennettAuthor Commented:
Wow... that was fast.

KEK: for /f "delims="  %D  in ('dir/ad/b') do attrib +s "%D"
This worked for folders with and without spaces in the name. This is just what i needed. Thanks!

BT1: For /f %i in ('dir /ad /b') do attrib +s %i
Just be sure it isn't Irish coffee...
This didn't work for folders with spaces in the name. I think all that may be required are double-quotes around the final %i. Thanks for the response though.

I guess I need to learn what delims does...
0
 
knightEknightCommented:
another way:

for /D  %D  in (*) do @echo attrib +s "%D"
0
 
knightEknightCommented:
travis, a split would have been appropriate here, don't you think?
0
 
travisjbennettAuthor Commented:
KEK: Good catch. I accepted the wrong solution, actually. How do I revise?
0
 
Christopher McKayCommented:
The delims option will use the default delimiters if you don't specify anything like I did. If you specify delimeters, it will take the delimeters you specify after the "=" in the "delims=" part of the command.

You can read more about the "For" command here:

http://ss64.com/nt/syntax-esc.html

Hope this helps!

:o)

Bartender_1
0
 
knightEknightCommented:
click the "request attention" link in lower right of your original question.  :)
0
 
Christopher McKayCommented:
and of course I link the wrong page. Sorry... here's the correct page:

http://ss64.com/nt/for.html

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 7
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now