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
Solved

dir command for just directories

Posted on 2013-10-22
9
359 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
  • 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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 95

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
How to record audio from input sources to your PC – connected devices, connected preamp to record vinyl discs, streaming media, that play through your audio card: Vista, Windows 7, Windows 8, Windows 8.1 and Windows 10 – both 32 bit & 64.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
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…

839 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