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

x
?
Solved

dir command for just directories

Posted on 2013-10-22
9
Medium Priority
?
368 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 85

Accepted Solution

by:
oBdA earned 500 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 500 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 70

Assisted Solution

by:KCTS
KCTS earned 500 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 85

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 500 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

Supports up to 4K resolution!

The VS192 2-Port 4K DisplayPort Splitter is perfect for anyone who needs to send one source of DisplayPort high definition video to two or four DisplayPort displays. The VS192 can split and also expand DisplayPort audio/video signal on two or four DisplayPort monitors.

Question has a verified solution.

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

Windows Server 2003 introduced persistent Volume Shadow Copies and made 2003 a must-do upgrade.  Since then, it's been a must-implement feature for all servers doing any kind of file sharing.
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

705 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