20 | 09 | 2017

Bulk Create Folder Shortcuts

The code below is copied from the Bulk Create Folder Shortcuts Program (see below). This program makes it possible to create folder shortcuts from all items in a specific path.

Create bulk shortcuts to folders



Use this code (or program) to set a path where the shortcuts will be saved. After that select a source folder to. Shortcuts will be made to all sub folders within the source folder. 

Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        If Me.txtfolder.Text = "Select folder" Then Exit Sub

        On Error GoTo errorhandler

        Dim Mypath As String, MyName As String, iCount As Integer
        iCount = 0

        Mypath = txtfolder.Text & "\"

        ' Set the path.
        MyName = Dir(Mypath, vbDirectory)   ' Retrieve the first entry.

        Do While MyName <> ""   ' Start the loop.
            ' Ignore the current directory and the encompassing directory.
            If MyName <> "." And MyName <> ".." Then
                ' Use bitwise comparison to make sure MyName is a directory.
                If (GetAttr(Mypath & MyName) And vbDirectory) = vbDirectory Then
                    Debug.Print(MyName)   ' Display entry only if it
                    Create_ShortCut(Mypath & MyName, ComboBox1.Text, (MyName), Mypath, 4, 4)

                    iCount = iCount + 1
                End If   ' it represents a directory.
            End If
            MyName = Dir()   ' Get next entry.


        Debug.Print("No.of Folders in the selected path : " & iCount)
        Exit Sub
    End Sub

    Sub Create_ShortCut(ByVal TargetPath As String, ByVal ShortCutPath As String, ByVal ShortCutname As String, _
Optional ByVal WorkPath As String = "0", Optional ByVal Window_Style As Integer = 0, Optional ByVal IconNum As Integer = 0)

        Dim VbsObj As Object
        VbsObj = CreateObject("WScript.Shell")

        Dim MyShortcut As Object
        ShortCutPath = VbsObj.SpecialFolders(ShortCutPath)
        MyShortcut = VbsObj.CreateShortcut(ShortCutPath & "\" & ShortCutname & ".lnk")
        MyShortcut.TargetPath = TargetPath
        MyShortcut.WorkingDirectory = WorkPath
        MyShortcut.WindowStyle = Window_Style
        MyShortcut.IconLocation = "C:\WINDOWS\system32\SHELL32.dll," & IconNum

    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'Fill the combobox with windows save locations

        Me.ComboBox1.Items.Add("Desktop") 'Desktop
        Me.ComboBox1.Items.Add("Programs") 'Start(Menu \ Programs)
        Me.ComboBox1.Items.Add("StartMenu") 'Start(Menu)
        Me.ComboBox1.Items.Add("StartUp") 'Start(Menu \ Programs \ StartUp)
        Me.ComboBox1.Items.Add("SendTo") 'Windows\SentTo
        Me.ComboBox1.Items.Add("Fonts") 'Fonts :Windows\Fonts
        Me.ComboBox1.Items.Add("Favorites") 'Favorites :Windows\Favorites"
        Me.ComboBox1.SelectedIndex = 0

    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        'Code to select the folder
        If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then

            txtfolder.Text = FolderBrowserDialog1.SelectedPath

        End If
    End Sub

End Class

 Download the source code or the stand allone program below.



Sign up now and upload your code to the website.

Help us to continue.....
Articles View Hits
Latest Articles