Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

Disk Operating System Commands in VBA

Introduction.

The Microsoft Disk Operating System (MS-DOS 1.0) was launched in 1982.  The first edition of Microsoft Windows 1.0 Operating System, Disk Operating system with Graphical User Interface (GUI), was released on November 20, 1985 – Source: www.wikipedia.org.  The Disk Operating System Version under Windows7 is 6.1.7600.

Disk Operating System Commands (both Internal and External) are directly used under the Command Prompt for managing Files, Folders on Disks, and for retrieving information on them.

DIR Command.

For example, the Directory Command (Dir /S/B/P) provides a list of all files with full Path Names (like C:\My Documents\New Folder\Resume.doc) from your C: Drive and display them on screen, one page at a time. 

Let us try an example.

Click on the Start Menu.

Type cmd and press Enter Key, DOS Command window will open up with the Command Prompt C:\>.  Type the following command to display a list of Folders/Files from your C: drive, one page at a time.  You must press a key to advance the list from one page to the other.

Warning:  The list of Folders/Files on your C: drive will run into hundreds of pages.  Press Ctrl+C (break the command) to terminate the list from displaying further.

C:\> Dir /S/B/P

C:\> is the command prompt

Dir (command stands for Directory)

Command switch /S includes Files in Sub-directories also in the output.

Command switch /B provides a bare-formatted list of files, i.e., gives only the file path names without creation date, file sizes, or any other information about the files.

Command switch /P displays the output on Screen one Page (one screen full) at a time.  Needs to press a key on the keyboard to advance the list of files to the next Page.

If you want to save the entire list into a text file, without page breaks, issue the following command with the output redirection symbol (>) with a text file name.  The re-direction symbol will send the output of the Directory command to a specified text file, without displaying them on the screen.

C:> Dir /S/B > myDirList.txt

Note: Leave a space on either side of the > symbol.

TYPE and MORE Command.

You may open the myDirList.txt file in Notepad and check the contents. You can display the contents of the myDirList.txt file with the following DOS Command:

C:\> TYPE myDirList.txt

Press Ctrl+C to stop the runaway display. The TYPE command displays the contents of a text file on screen. But, it will not display the output one screen full at a time. To do that, we can seek the help of another DOS command: MORE with the use of the piping symbol (|).

C:\> TYPE myDirList.txt | MORE

In the above command we are using the piping symbol (|) to join the TYPE filename.txt | MORE commands to get the required output. The TYPE command reads the text file contents and pass it on to the next command MORE, without directly sending the output to the Screen. MORE Command takes its input from the TYPE command, through the pipe, and displays it one screen-full at a time. Press SPACEBAR to display the next screen-full of text.

OR

C:\> MORE < myDirList.txt

If > (greater than) symbol is known as a re-direction symbol in DOS, then < (less than) symbol is known as a Source symbol for the MORE command. The MORE command reads data from the filename given immediately after the Source Symbol (<) and displays one screen-full at a time.

DIR Command in VBA.

Let us come back to the Dir Command, it is available in VBA also. But it is used for a different purpose. We can use this command to check the presence of a particular file or the existence of any file in a folder. The usage of this command is as shown below:

strOutput = Dir("C:\My Documents\Resume.doc", vbNormal)

The Dir command checks for the presence of Word File Resume.doc in Folder C:\My Documents, if found, then the file name 'Resume.doc' is returned in strOutput Variable, otherwise, it will return an empty string.

strOutput = Dir("C:\My Documents\*.*", vbNormal)

This command will get the first file name, from the specified folder, and returns it in strOutput Variable. You may try out this command in the Debug Window directly, like:

? Dir("C:\My Documents\*.*")

This will print the first file name found in the folder C:\My Documents in the Debug Window. To get subsequent file names from the same folder you can run the command without any parameters to the function, like:

? Dir()

Note: First time when you run this Command you should provide a Path as a parameter, otherwise it will end up with the error.

Place the insertion point on the Dir() Command and press F1 to display the details of this Command in Access Help Documents.

There are other interesting Windows Operating System Commands like ChDrive, ChDir, MkDir, RmDir, etc., and we will learn their usage in VBA Next week.

Earlier Post Link References:

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