Updated code from your other thread.
1 Button, 1 ProgressBar
Imports System.IO
Public Class Form1
Private sTemp1, sTemp2 As String '// TEMP.Strings, used as needed.
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim fbd As New FolderBrowserDialog : sTemp1 = "" : sTemp2 = ""
With fbd
.Description = "Select a folder to copy the content FROM..." '// Source.Folder
If .ShowDialog = Windows.Forms.DialogResult.OK Then sTemp1 = .SelectedPath
.Description = "Select a folder to copy the content TO..." '// Destination.Folder
If .ShowDialog = Windows.Forms.DialogResult.OK Then sTemp2 = .SelectedPath
If Not sTemp1 = "" OrElse Not sTemp2 = "" Then copyDirectory(sTemp1, sTemp2, , ProgressBar1)
End With
End Sub
Private Sub copyDirectory(ByVal selCoolSourcePath As String, ByVal selDestinationPath As String, Optional selCoolFileExtension As String = "*.*", Optional selCoolProgressBar As ProgressBar = Nothing)
sTemp1 = ""
With selCoolProgressBar
If Not selCoolProgressBar Is Nothing Then '// if ProgressBar sent, set .Value and .Maximum.
.Value = 0
.Maximum = Directory.GetFiles(selCoolSourcePath, selCoolFileExtension, IO.SearchOption.AllDirectories).Length
End If
If Not Directory.Exists(selDestinationPath) Then Directory.CreateDirectory(selDestinationPath) '// create Folder if needed.
For Each myCoolFile As String In My.Computer.FileSystem.GetFiles _
(selCoolSourcePath, FileIO.SearchOption.SearchAllSubDirectories, selCoolFileExtension) '// loop thru Source.Files.
sTemp1 = selDestinationPath & "\" & Path.GetFileName(myCoolFile) '// set .DestinationPath w/only the filename+extension.
If Not File.Exists(sTemp1) Then '// if .File Not.Exist, procced, Else it will error "for.now".
File.Copy(myCoolFile, sTemp1) '// copy File.over.
Else
' MsgBox("File.Exists in Destination.Folder, cannot copy." & vbNewLine & sTemp1, MsgBoxStyle.Information)
End If
If Not selCoolProgressBar Is Nothing Then .Value += 1 '// +=1 .Value, if ProgressBar sent.
Next
End With
MsgBox(".done.", MsgBoxStyle.Information)
End Sub
End Class
.line: 16. Private Sub copyDirectory(...) , has an Optional file.extension. It is currently set to get all files ("*.*") , though it can be set to only get certain file .extension types.
If Not sTemp1 = "" OrElse Not sTemp2 = "" Then copyDirectory(sTemp1, sTemp2, "*.png", ProgressBar1)
Hope this helps. :)
codeorder
Postaholic
2,124 posts since Aug 2010
Reputation Points: 256
Solved Threads: 387
Skill Endorsements: 8
codeorder
Postaholic
2,124 posts since Aug 2010
Reputation Points: 256
Solved Threads: 387
Skill Endorsements: 8
Add this just below line 11.
'/////////////////
With Path.GetDirectoryName(subdir)
MsgBox(.Substring(.LastIndexOf("\") + 1)) '// getFolderName only. :)
'//////
End '// TERMINATE APPLICATION (FOR TESTING)
End With
'/////////////////
codeorder
Postaholic
2,124 posts since Aug 2010
Reputation Points: 256
Solved Threads: 387
Skill Endorsements: 8
q.q.(quick.question)
.what exactly are you trying to do? GetFolderName And Then what???
If it is to create the Directory and place the File in it, see if this helps.
Public Sub xNewCoolFolder(ByVal selCoolFolder As String)
If Not Directory.Exists(selCoolFolder) Then Directory.CreateDirectory(selCoolFolder)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
xNewCoolFolder(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\myCoolFolder")
End Sub
Might help if you create a new Directory andThen .Move.File.over.
codeorder
Postaholic
2,124 posts since Aug 2010
Reputation Points: 256
Solved Threads: 387
Skill Endorsements: 8
From the code posted and the link to get a ListBox loaded w/the sub.directories, I think that, sec...
Might help if you create a new Directory andThen .Move.File.over.
...into that New.Directory.
.my.apologies "vb.noob":D, I left some info out.:)
codeorder
Postaholic
2,124 posts since Aug 2010
Reputation Points: 256
Solved Threads: 387
Skill Endorsements: 8