Solved

dir command for just directories

Posted on 2013-10-22
9
354 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 83

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
 
LVL 70

Assisted Solution

by:KCTS
KCTS earned 125 total points
ID: 39590580
dir drive: /d
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 83

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Several part series to implement Internet Explorer 11 Enterprise Mode
NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now