Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

batch file for syntax problem windows 7 cmd prompt

Posted on 2014-02-14
4
Medium Priority
?
978 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Expert Comment

by:Andrej Pirman
ID: 39860230
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 41

Accepted Solution

by:
footech earned 2000 total points
ID: 39860231
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
ID: 39860237
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
ID: 39860257
That was it.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
A quick guide on how to use Group Policy to create a custom power plan and set it active on Windows 7.
This Micro Tutorial will give you basic overview of the control panel section on Windows 7. It will depth in Network and Internet, Hardware and Sound, etc. This will be demonstrated using Windows 7 operating system.
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.

670 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