Module: ShellFileDisk in Category Windows : File and Disk Operations from Total Visual SourceBook

Windows shell routines to work with folder and disk in VB6 and VBA with 32 and 64-bit Windows API calls.

The Windows Shell user interface exposes its functionality through a variety of functions exported from the SHELL32.DLL library. This module makes it easy to use this functionality in your applications.

Procedure Name Type Description
(Declarations) Declarations Declarations and private variables for the modShellFileDisk module.
AddToRecentDocs Procedure Add a file to the 'Documents' submenu on the Windows Start menu.
ClearRecentDocs Procedure Clear the list of recently opened documents from the Windows Start menu.
GetShellAppdataLocation Procedure Get the path of the user's AppData folder.
GetShellCommonDesktopDirectoryLocation Procedure Get the path of the user's CommonDesktopDirectory folder.
GetShellCommonProgramsLocation Procedure Get the path of the user's CommonPrograms folder.
GetShellCommonStartMenuLocation Procedure Get the path of the user's CommonStartMenu folder.
GetShellCommonStartupLocation Procedure Get the path of the user's CommonStartup folder.
GetShellDesktopDirectoryLocation Procedure Get the path of the user's DesktopDirectory folder.
GetShellDesktopLocation Procedure Get the path of the user's Desktop folder.
GetShellFavoritesLocation Procedure Get the path of the user's Favorites folder.
GetShellFontsLocation Procedure Get the path of the user's Fonts folder.
GetShellPersonalLocation Procedure Get the path of the user's Personal folder.
GetShellProgramsLocation Procedure Get the path of the user's Programs folder.
GetShellRecentLocation Procedure Get the path of the user's Recent folder.
GetShellSendToLocation Procedure Get the path of the user's SendTo folder.
GetShellStartMenuLocation Procedure Get the path of the user's StartMenu folder.
GetShellStartupLocation Procedure Get the path of the user's Startup folder.
GetShellTemplatesLocation Procedure Get the path of the user's Templates folder.
ShellCopyFile Procedure Copy a file or files to a single destination.
ShellFormatDisk Procedure Show the Windows shell format disk dialog.
ShellRecycleFile Procedure Send the specified file or files to the Windows recycle bin.
' Example of modShellFileDisk
'
' To try this example, do the following:
' 1. Create a new form
' 2. Create a list box named 'lstExample'
' 3. Create the following command buttons
'       'cmdTest'
'       'cmdRecentDocs'
'       'cmdFileOps'
'       'cmdFormat'
' 4. Paste all the code from this example to the new form's module.

' This example assumes that the sample files are located in the folder named by the following constant.
Private Const mcstrSamplePath As String = "C:\Total Visual SourceBook 2013\Samples\"

Private Sub cmdFormat_Click()
  ' Example of ShellFormatDisk
  ' Uncomment this routine in order to test it on your machine

  Dim fResult As Boolean

  'If MsgBox("Are you sure you want to format the A drive?", vbYesNo) = vbYes Then
  '  fResult = ShellFormatDisk(Me.hwnd, "a", True, False, False)
  'End If

  MsgBox fResult

End Sub

Private Sub cmdTest_Click()
  Dim strOutput As String

  With lstExample
    ' clear the list.  In VB6 use .Clear
    .RowSource = ""

    ' Example of GetShellAppdataLocation
    .AddItem "----- GetShellAppdataLocation -----"
    strOutput = GetShellAppdataLocation(Me.hWnd)
    .AddItem strOutput

    ' Example of GetShellCommonDesktopDirectoryLocation
    .AddItem "----- GetShellCommonDesktopDirectoryLocation -----"
    strOutput = GetShellCommonDesktopDirectoryLocation(Me.hWnd)
    .AddItem strOutput

    ' Example of GetShellCommonProgramsLocation
    .AddItem "----- GetShellCommonProgramsLocation -----"
    strOutput = GetShellCommonProgramsLocation(Me.hWnd)
    .AddItem strOutput

    ' Example of GetShellCommonStartMenuLocation
    .AddItem "----- GetShellCommonStartMenuLocation -----"
    strOutput = GetShellCommonStartMenuLocation(Me.hWnd)
    .AddItem strOutput

    ' Example of GetShellCommonStartupLocation
    .AddItem "----- GetShellCommonStartupLocation -----"
    strOutput = GetShellCommonStartupLocation(Me.hWnd)
    .AddItem strOutput

    ' Example of GetShellDesktopDirectoryLocation
    .AddItem "----- GetShellDesktopDirectoryLocation -----"
    strOutput = GetShellDesktopDirectoryLocation(Me.hWnd)
    .AddItem strOutput

    ' Example of GetShellDesktopLocation
    .AddItem "----- GetShellDesktopLocation -----"
    strOutput = GetShellDesktopLocation(Me.hWnd)
    .AddItem strOutput

    ' Example of GetShellFavoritesLocation
    .AddItem "----- GetShellFavoritesLocation -----"
    strOutput = GetShellFavoritesLocation(Me.hWnd)
    .AddItem strOutput

    ' Example of GetShellFontsLocation
    .AddItem "----- GetShellFontsLocation -----"
    strOutput = GetShellFontsLocation(Me.hWnd)
    .AddItem strOutput

    ' Example of GetShellPersonalLocation
    .AddItem "----- GetShellPersonalLocation -----"
    strOutput = GetShellPersonalLocation(Me.hWnd)
    .AddItem strOutput

    ' Example of GetShellProgramsLocation
    .AddItem "----- GetShellProgramsLocation -----"
    strOutput = GetShellProgramsLocation(Me.hWnd)
    .AddItem strOutput

    ' Example of GetShellRecentLocation
    .AddItem "----- GetShellRecentLocation -----"
    strOutput = GetShellRecentLocation(Me.hWnd)
    .AddItem strOutput

    ' Example of GetShellSendToLocation
    .AddItem "----- GetShellSendToLocation -----"
    strOutput = GetShellSendToLocation(Me.hWnd)
    .AddItem strOutput

    ' Example of GetShellStartMenuLocation
    .AddItem "----- GetShellStartMenuLocation -----"
    strOutput = GetShellStartMenuLocation(Me.hWnd)
    .AddItem strOutput

    ' Example of GetShellStartupLocation
    .AddItem "----- GetShellStartupLocation -----"
    strOutput = GetShellStartupLocation(Me.hWnd)
    .AddItem strOutput

    ' Example of GetShellTemplatesLocation
    .AddItem "----- GetShellTemplatesLocation -----"
    strOutput = GetShellTemplatesLocation(Me.hWnd)
    .AddItem strOutput
  End With
End Sub

Private Sub cmdFileOps_Click()

  Dim strFile As String
  Dim strDest As String

  strFile = mcstrSamplePath & "test.txt"
  strDest = mcstrSamplePath & "testcopy.txt"

  ' Example of ShellCopyFile
  ShellCopyFile Me.hWnd, strFile, strDest, False, "Copy file test..."

  If MsgBox("Is it OK to recycle the file just copied?", vbYesNo + vbQuestion) = vbYes Then
    ' Example of ShellRecycleFile
    ShellRecycleFile Me.hWnd, strDest, True, "Deleting test file"
  End If

End Sub

Private Sub cmdRecentDocs_Click()
  Dim strDoc As String

  strDoc = mcstrSamplePath & "test.txt"

  ' Example of AddToRecentDocs
  AddToRecentDocs strDoc
  MsgBox "The document " & strDoc & " was added to the Recent Document list"

  If MsgBox("Is it OK to clear your list of recent docs?", vbYesNo + vbQuestion) = vbYes Then
    ' Example of ClearRecentDocs
    ClearRecentDocs
  End If

End Sub

Private Sub Form_Load()
  cmdTest.Caption = "Test"
  cmdRecentDocs.Caption = "Recent Docs"
  cmdFileOps.Caption = "File Operations"
  cmdFormat.Caption = "Format"

  ' By default, this it Table/Query but we want to specify our own list of values from code
  lstExample.RowSourceType = "Value List"
End Sub

Total Visual SourceBook The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.

Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!

Additional Resources

Total Visual SourceBook CD and Printed Manual

Microsoft Access/ Office 2016, 2013, 2010, and 2007 Version
is Shipping!

New features in Total Visual SourceBook for Access, Office and VB6

Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!


View all FMS products for Microsoft Access All Our Microsoft Access Products

Reviews

Reader Choice Award for MS Access Source Code Library
Reader Choice

"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."

Van T. Dinh, Microsoft MVP

SourceBook Info

Additional Info

Question

 

 

Free Product Catalog from FMS