Solved

batch file for syntax problem windows 7 cmd prompt

Posted on 2014-02-14
4
896 Views
Last Modified: 2014-02-14
Having problems with a batch file which runs a command on each subfolder.  Googling has told me this should list each subfolder name.  It does not.  It lists 'dir' then '/b'.  It is treating the array as literal text rather than the output of the dir /b * command.

for /d %%a in ('dir /b *') do echo %%a || icacls %%! | find /i "domain users"

I am trying to run icacls on each folder and search the output for "domain users" to see what the permissions are for domain users.
0
Comment
Question by:YMartin
  • 2
4 Comments
 
LVL 18

Expert Comment

by:Andrej Pirman
Comment Utility
I suggest you do it in two steps:

dir c:\some_folder /A:D /D /B>userlist.txt
FOR /f %%D IN (userlist.txt) DO (
ECHO %%a || icacls %%! | find /i "domain users"
)
0
 
LVL 39

Accepted Solution

by:
footech earned 500 total points
Comment Utility
If you use the /d switch, then inside the parentheses is a set of one or more files.  If you want to run the command "dir /b" and work on its output, then you need to use the /f switch instead.
for /f %%a in ('dir /b *') do echo %%a

Open in new window

0
 
LVL 18

Expert Comment

by:Andrej Pirman
Comment Utility
Also, peek at this page might give you some ideas:
http://www.robvanderwoude.com/ntadmincommands.php#Cmd09
0
 
LVL 1

Author Closing Comment

by:YMartin
Comment Utility
That was it.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now