Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.


Dir Disk Operating System (DOS) Command is available in Microsoft Access VBA too. Usage of this command in VBA is for checking the presence of Files/Folder on Disk. But, do you ever thought of taking a listing of all the folders/files with their complete pathname, starting from it's root (C:\folder\folder\folder.. or C:\folder\folder\folder\Filename), for future reference or simply for reviewing your disk usage and maintenance.

Way back in 1996-97, when it was time to change our Corporate LAN Software from Novell Netware to Windows NT System all the User Departments are asked to review their Server folder structure and to remove unused or unwanted folders/files so that old Server contents can be migrated to the new Windows NT Server.  This requirement encouraged me to take a closer look at the DIR command. With the help of combining few optional parameters of the command I was able to prepare a listing of all the folders of our department Server, taken from Windows 95 Client Machine’s mapped Server Drive. This listing helped a lot to review the folders and remove obsolete folders/files.

You can take a listing of folders using either DIR command or TREE command. Both commands produces different style of listings. I prefer the DIR command. TREE command creates a graphical listing, showing hierarchical placement of each folder. DIR command displays all the folders and sub-folder(s) separated with back-slashes in one line. Sample listing of both types are given below, one after the other:

DIR Command have several optional parameters to prepare listings in different ways depending on your requirements. Most of the time we ignore these options because of their usage is not common.

You can get a list of all optional parameters with a simple help command parameter (/?). Usage is as given below. First let us open the DOS Command Window.

  1. Right-Click on Windows Start Button and click on Run command.
  2. Type cmd in the Open control and click OK to open the DOS Command Prompt.
  3. If the prompt appears as something like C:\Users\User> then Type:
    Cd \ then press Enter key to set the prompt to C:\>

    Cd stands for Change Directory command. \ is the name of the Root Folder. This will set drive C root folder as current.

    Tip:Type Exit in the command prompt and press Enter Key to close the DOS Window, any time you want.

  4. Type the following command to display a list of optional parameters of DIR command:
    DIR /?

You can display the details of any DOS command and their usage in this way, by typing the Command followed by /? in the DOS Command prompt.

Now, let us display the listing of all the folders in C: drive on the screen.

Warning:Don't say I didn't warn you that this will be a lengthy list and may take few minutes to display all of them on the screen.

Tip: You may terminate the listing at any point by pressing Ctrl+C Keys.

Type the following Command in the DOS Prompt and press Enter Key.

C:/>DIR /A:D/S/B/P

Let us take a look at each parameter given with the DIR command.

  • /A - Display files with specific Attributes. Specific attributes are given separated by a colon like /A:D D - for directories.
  • /S - include Sub-folders also in the listing.
  • /B - take a Bare-format listing and exclude summary information.
  • /P - display the listing Page-wise (Pause the listing when a screen-full of information is displayed. Press any key to display the next page).

If you need listing of a particular folder and it's sub-folders only then include the folder name in the command as given below:


By default, DOS Command's output is directly sent to the screen for viewing. If you need a printout on paper then we must save the output into a text file. This method uses a output re-direction symbol (>) followed by a text file name. The following command saves the output to the FolderList.txt file.

C:/>DIR "\RADIO" /A:D/S/B > FolderList.txt

NB: If you are taking a listing of all the folders and sub-folders/files of a disk then it will take some time to save all the details in the text file and complete the command. It may look like the computer hanged, have patience and wait for the DOS prompt C:/> to re-appear. If you run out of patience and would like to terminate the command then press Ctrl+C Keys.

You may open the text file FolderList.txt in any plain text editor program to take printouts.

You may use the following DOS command to display the contents of the text file:

Type FolderList.txt | More

Type - Displays the contents of the text file on the screen.

| (verical bar) this symbol is known as Piping Symbol. The piping symbol ensures that the output of Type command is passed to the next command More. More command displays the output one screen-full at a time, like the /P parameter to the DIR command. Press a Key to display the next page.

TREE command displays folder list in a hierarchical structure.

C:/>TREE | More

Displays folder structure listing page-wise.

C:/>TREE/F | More

/F parameter displays folder names followed by Filenames.

Hope you have enjoyed doing some thing different and useful.


No comments:

Post a Comment


Your email address:

Delivered by FeedBurner


Infolinks Text Ads

blog.feedspot.com Microsoft Access Blogs

Popular Posts

Search This Blog

Blog Archive

Powered by Blogger.


Forms How Tos Functions MS-Access Security Reports msaccess forms Animations msaccess animation Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Queries External Links msaccess reports msaccess tips Accesstips Menus and Toolbars MsaccessLinks Process Controls Art Work Downloads msaccess How Tos Graph Charts msaccessQuery Array List Boxes Command Buttons Emails and Alerts Property Query Class Module Combo Boxes Custom Wizards DOS Commands Data Data Type Objects VBA ms-access functions msaccess functions msaccess graphs msaccess reporttricks Calculation msaccessprocess security advanced Access Security Custom Functions Field Type Macros Menus Object Reference Report Top Values Variables msaccess email msaccess menus progressmeter Access2007 Auto-Number Command Button Copy Expression Fields Form Form Instances Join Methods Microsoft Numbering System Records Recordset Security Split SubForm Table Utility Workgroup database msaccess wizards Access2003 Accounting Year Action Animation Attachment Binary Numbers Bookmarks Budgeting ChDir Color Palette Conditional Formatting Controls Data Filtering Defining Pages Diagram Disk Dynamic Lookup Error Handler Excel Export External Filter Formatting Groups Hexadecimal Numbers Import Labels List Logo Macro Mail Merge Main Form Memo Monitoring Octal Numbers Operating System Paste Primary-Key Product Rank Reading Rich Text Sequence SetFocus Summary Tab-Page Tables Time Difference Union Query User Users Water-Mark Word automatically commands function hyperlinks iSeries Date iif ms-access msaccess msaccess alerts pdf files reference restore switch text toolbar tutorial updating upload vba code

Featured Post

Access Class Module and Wrapper Classes

There are times that a particular Class Module needs to be instantiated more than once, to use similar set of values for a particular Applic...


Blog Archive

Recent Posts