Solved

dir command for just directories

Posted on 2013-10-22
9
364 Views
Last Modified: 2013-10-23
Is it possible to run a DIR command on a share to list only top level folders on that share, i.e. those that reside in the root directory, i.e.

\\server\share\dir1 \\server\share\dir2 \\server\share\dir3

Can you provide syntax
0
Comment
Question by:pma111
[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
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 125 total points
ID: 39590561
Try
dir /a:d "\\server\share"
or
dir /a:d /b "\\server\share"
or
for /d %a in ("\\server\share\*.*") do @echo %a
For the last to be used in a batch file, use double percent signs:
for /d %%a in ("\\server\share\*.*") do @echo %%a
0
 
LVL 3

Author Comment

by:pma111
ID: 39590564
can you just elaborate how the above works, i.e. what each switch is actually doing? thanks
0
 
LVL 10

Assisted Solution

by:ecarbone
ecarbone earned 125 total points
ID: 39590565
From a command prompt, to list ONLY the directories (and not any actual files):

dir \\server\share\dir1 /ad

The above commend will list the date, time, type and directory name.

If you want just a bare-bones list, use this instead:

dir \\server\share\dir1 /ad /b

To save that list as a text file, use this:

dir \\server\share\dir1 /ad /b > mylist.txt
0
Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

 
LVL 70

Assisted Solution

by:KCTS
KCTS earned 125 total points
ID: 39590580
dir drive: /d
0
 
LVL 3

Author Comment

by:pma111
ID: 39590581
can you explain what the switches used in that command actually do?
0
 
LVL 70

Expert Comment

by:KCTS
ID: 39590585
/d - list directories
0
 
LVL 70

Expert Comment

by:KCTS
ID: 39590589
0
 
LVL 84

Expert Comment

by:oBdA
ID: 39590639
Only list elements with the attribute "directory": /a:d
dir /a:d "\\server\share"
Use "bare" output (just file/folder names, no header, no summary, no additional file information): /b
dir /a:d /b "\\server\share"
Do a loop processing (for ...), working only with directories (/d), and echo each loop element (which results in the full UNC path); the "@" in front of "echo" suppresses the command output for the current command:
for /d %a in ("\\server\share\*.*") do @echo %a
Enter "help for" for details about "for" loops.
0
 
LVL 96

Assisted Solution

by:Lee W, MVP
Lee W, MVP earned 125 total points
ID: 39590935
If you want to know what the switches do, type the command /? and it will tell you.

dir /?
for /?

Or reference the command at www.ss64.com which is basically a web site someone put together that COPIES the info from /?
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

751 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