Hallo,
De bedoeling is om een hoofddirectory en subdirectory te kopieren naar een ander directory, dus als voorbeeld:
Video(hoofddir)---films(subdir) titels van films(files)
Video----films-----de film.avi
Op formulier1 heb ik en button om het kopieren te starten.
Verder heb ik een class zie hieronder:
Wat plaats ik nu onder de button om deze class te benaderen.
Misschien doe ik het ook allemaal verkeerd en kan het eenvoudiger.
Ik heb hier wel naar gegoogled maar kom alleen hierop uit
Vriendelijke groet
De bedoeling is om een hoofddirectory en subdirectory te kopieren naar een ander directory, dus als voorbeeld:
Video(hoofddir)---films(subdir) titels van films(files)
Video----films-----de film.avi
Op formulier1 heb ik en button om het kopieren te starten.
Verder heb ik een class zie hieronder:
Code:
Imports System
Imports System.IO
Class DirectoryCopyExample
Shared Sub Main()
' Copy from the current directory, include subdirectories.
DirectoryCopy(Form1.ListBox1.SelectedItem, Form1.CompleetPad.Text, True)
End Sub
Private Shared Sub DirectoryCopy(
ByVal sourceDirName As String,
ByVal destDirName As String,
ByVal copySubDirs As Boolean)
' Get the subdirectories for the specified directory.
Dim dir As DirectoryInfo = New DirectoryInfo(Form1.ListBox1.SelectedItem)
If Not dir.Exists Then
Throw New DirectoryNotFoundException(
"Source directory does not exist or could not be found: " _
+ Form1.ListBox1.SelectedItem)
End If
Dim dirs As DirectoryInfo() = dir.GetDirectories()
' If the destination directory doesn't exist, create it.
If Not Directory.Exists(destDirName) Then
Directory.CreateDirectory(destDirName)
End If
' Get the files in the directory and copy them to the new location.
Dim files As FileInfo() = dir.GetFiles()
For Each file In files
Dim temppath As String = Path.Combine(destDirName, file.Name)
file.CopyTo(temppath, False)
Next file
' If copying subdirectories, copy them and their contents to new location.
If copySubDirs Then
For Each subdir In dirs
Dim temppath As String = Path.Combine(destDirName, subdir.Name)
DirectoryCopy(subdir.FullName, temppath, copySubDirs)
Next subdir
End If
End Sub
End Class
Wat plaats ik nu onder de button om deze class te benaderen.
Misschien doe ik het ook allemaal verkeerd en kan het eenvoudiger.
Ik heb hier wel naar gegoogled maar kom alleen hierop uit
Vriendelijke groet