Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

DIR TREE DOS COMMANDS

Introduction.

Dir Disk Operating System (DOS) Command is available in Microsoft Access VBA too. The usage of this command in VBA is for checking the presence of Files / Folders on the Disk. But, do you ever thought of taking a listing of all the folders/files with their complete pathname, starting from its 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 advised 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 a few optional parameters of the command, I was able to prepare a listing of all the folders and sub-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 the DIR command or the TREE command. Both commands produce different styles of listings. I prefer the DIR command. The TREE command creates a graphical listing, showing the hierarchical placement of each folder. DIR command displays all the folders and sub-folder(s) separated with back-slashes in one line. A sample listing of both types is given below, one after the other:

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

DOS Command Help.

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

  1. Right-click on Windows Start Button and click on the 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. The \ is the name of the Root Folder. This will set the Disk Drive C root folder as current.

    Tip: Type the Command Exit and press the Enter key to close the DOS Window, any time you want.

  4. Type the following command to display a list of optional parameters of the 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.

Display Folders in C: Drive.

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 a 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.

DIR Command and its few Options.

  • /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 a listing of a particular folder and its sub-folders only then include the folder name in the command as given below:

C:/>DIR "\RADIO" /A:D/S/B/P

Saving the DIRectory Listing to File.

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 an 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.

The TYPE of Command.

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.

| (The vertical bar) this symbol is known as Piping Symbol. The piping symbol ensures that the output of the Type command is passed to the next command More. The 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.

The TREE Command.

The TREE command displays the folder list in a hierarchical structure.

C:/>TREE | More

Display folder structure listing page-wise.

C:/>TREE/F | More

/F parameter display folder names followed by Filenames.

Hope you have enjoyed doing something different and useful.

Share:

No comments:

Post a Comment

Comments subject to moderation before publishing.

PRESENTATION: ACCESS USER GROUPS (EUROPE)

Translate

PageRank

Post Feed


Search

Popular Posts

Blog Archive

Powered by Blogger.

Labels

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