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

Comments are subject to moderation before publishing.


Subscribe in a reader
Your email address:

Delivered by FeedBurner

Blog Directory Visit blogadda.com to discover Indian blogs


Popular Posts

Search This Blog

Blog Archive

Powered by Blogger.

Follow by Email


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

Featured Post

ROUNDDOWN Function of Excel

We have introduced ROUNDUP() Function of Excel in Microsoft Access earlier.  It works like ROUND() Function except that the number is alway...


Blog Archive

Recent Posts