Solved

dir command for just directories

Posted on 2013-10-22
9
362 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

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.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Learn how to PXE Boot both BIOS & UEFI machines with DHCP Policies and Custom Vendor Classes
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
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…

713 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