Hi everybody,
I've been working on a tool which creates a complete folder structure for each project I work on.
At the start of the project, a project data and a media folder are created. When the layout of the project is clear, so called Service Objects should be created. Each of these get their own folder in a specific directory. In the project data directory I would like to have shortcuts to the Service Object folders.
I found a snippet of code online and tried to incorporate it, but I'm obviously doing something wrong.
Any help is much appreciated!
Please see code below:
![Name: Folder Structure Creator.jpg
Views: 30
Size: 12.2 KB]()
I've been working on a tool which creates a complete folder structure for each project I work on.
At the start of the project, a project data and a media folder are created. When the layout of the project is clear, so called Service Objects should be created. Each of these get their own folder in a specific directory. In the project data directory I would like to have shortcuts to the Service Object folders.
I found a snippet of code online and tried to incorporate it, but I'm obviously doing something wrong.
Any help is much appreciated!
Please see code below:
Code:
Imports IWshRuntimeLibrary
Public Class Form5a
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
'Create project and media folders
'declare variables
Dim CN, CC, CL, CA, AN, PRN, SD As String
CN = Me.TextBox1.Text
CC = Me.ComboBox11.Text
CL = Me.TextBox2.Text
CA = Me.TextBox3.Text
AN = Me.TextBox4.Text
PRN = Me.TextBox5.Text
Dim substring As String
substring = Strings.Right(CC, 4)
SD = CL & " " & substring & " - " & CA
'compile path
If System.IO.Directory.Exists("K:\Master Data Management\02. External Projects\" & PRN) = True Then
MessageBox.Show("Project directory already exists!")
Else
System.IO.Directory.CreateDirectory("K:\Master Data Management\02. External Projects\" & PRN)
My.Computer.FileSystem.CopyDirectory("K:\Master Data Management\02. External Projects\00. Folder Templates\Folder Template - Order\00000 - [bestemmingsrelatie]", "K:\Master Data Management\02. External Projects\" & PRN)
MessageBox.Show("Project directory succesfully created!")
End If
If System.IO.Directory.Exists("\\Nas01\Mediadisk\External Projects\" & CN & "\" & SD & "\" & "Area" & " " & AN & "\") = True Then
MessageBox.Show("Media directory already exists!")
Else
System.IO.Directory.CreateDirectory("\\Nas01\Mediadisk\External Projects\" & CN & "\" & SD & "\" & "Area" & " " & AN & "\")
My.Computer.FileSystem.CopyDirectory("\\Nas01\Mediadisk\External Projects\00. Folder Templates\Naam bestemmingsrelatie\Plaats (landcode) - Adres\Area No", "\\Nas01\Mediadisk\External Projects\" & CN & "\" & SD & "\" & "Area" & " " & AN & "\")
MessageBox.Show("Media directory succesfully created!")
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim CN, PRN As String
CN = Me.TextBox1.Text
PRN = Me.TextBox5.Text
Process.Start("explorer.exe", "K:\Project Data\02. External Projects\" & PRN)
Process.Start("explorer.exe", "\\Nas01\Mediadisk\External Projects\" & CN)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'create Folders for Service Objects
Dim Foldername As String
Dim CN, CC, CL, CA, AN, SD, PRN As String
CN = Me.TextBox1.Text
CC = Me.ComboBox11.Text
CL = Me.TextBox2.Text
CA = Me.TextBox3.Text
AN = Me.TextBox4.Text
PRN = Me.TextBox5.Text
Dim substring As String
substring = Strings.Right(CC, 4)
SD = CL & " " & substring & " - " & CA
For Each Foldername In Me.ListBox2.Items
System.IO.Directory.CreateDirectory("K:\Master Data Management\01. Service Objects\" & Foldername)
'create shortcuts for all Service Object folders
Dim WshShell As New IWshShell_Class
Dim MyShortcut As IWshRuntimeLibrary.IWshShortcut
Dim DestFolder As String = Environment.GetFolderPath("K:\Project Data\02. External Projects\" & PRN)
MyShortcut = CType(WshShell.CreateShortcut(DestFolder \ Foldername & ".lnk"), IWshRuntimeLibrary.IWshShortcut)
MyShortcut.TargetPath = "K:\Master Data Management\01. Service Objects\" & Foldername
MyShortcut.Save()
'create Service Object folders in related Customer folder on NAS
System.IO.Directory.CreateDirectory("\\Nas01\Mediadisk\External Projects\" & CN & "\" & SD & "\" & "Area" & " " & AN & "\" & "02. Production" & "\" & Foldername)
System.IO.Directory.CreateDirectory("\\Nas01\Mediadisk\External Projects\" & CN & "\" & SD & "\" & "Area" & " " & AN & "\" & "04. Installation" & "\" & Foldername)
System.IO.Directory.CreateDirectory("\\Nas01\Mediadisk\External Projects\" & CN & "\" & SD & "\" & "Area" & " " & AN & "\" & "05. Aftersales" & "\" & Foldername)
My.Computer.FileSystem.CopyDirectory("K:\Master Data Management\01. Service Objects\00. Folder Template - Service Objects\[SON] - [SOD]-[(SOC)]", "K:\Master Data Management\01. Service Objects\" & Foldername)
Next
MessageBox.Show("Service Object directories succesfully created!")
End Sub
'Add
Private Sub Add(text As String)
Dim SON, SOD, PUC, SOC As String
SON = Me.NumericUpDown1.Value
SOD = Me.ComboBox1.Text
SOC = Me.NumericUpDown2.Value
'create PUC abbreviation
If SOD = "Box Handling" Then
PUC = "BH"
End If
If SOD = "Buffer System" Then
PUC = "BS"
End If
If SOD = "Cart Handling" Then
PUC = "CH"
End If
If SOD = "Filling System" Then
PUC = "FS"
End If
If SOD = "Information System" Then
PUC = "IS"
End If
If SOD = "Packing Line" Then
PUC = "PL"
End If
If SOD = "Palletising System" Then
PUC = "PS"
End If
If SOD = "Tipping System" Then
PUC = "TS"
End If
'merge to text string
text = SON & " " & "-" & " " & SOD & " " & "(" & PUC & SOC & ")"
ListBox2.Items.Add(text)
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Add(Text)
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Dim selected As String = Me.ListBox2.SelectedItem.ToString
If selected IsNot "" Then
Me.ListBox2.Items.Remove(selected)
End If
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
Me.ListBox2.Items.Clear()
End Sub
End Class