tomislav91
New member
- Joined
- Jun 7, 2015
- Messages
- 1
- Programming Experience
- 1-3
I have problem with my copying folder, where exist another with same name. Idea is to save folder and give (1) in name, like windows does.
So, if have folder name Test, it must save Test (1)...
With files everything is OK, but problem is with folders, nothing happend, no errors, no nothing...And in destination path is the same, nothing happens...Where is mistakE?
and this is function
So, if have folder name Test, it must save Test (1)...
With files everything is OK, but problem is with folders, nothing happend, no errors, no nothing...And in destination path is the same, nothing happens...Where is mistakE?
VB.NET:
If System.IO.Directory.Exists(destinationFolderPath) Then
Dim nextAvialableFolderPath As String = GetDestinationFolderPath(txtFolderNetworkPath.Text, System.IO.Path.GetDirectoryName(originalFolderPath))
Select Case MessageBox.Show("the file already exists would you like to overwrite (click yes) or keep both (click no) to cancel operation click cancel", "Error", MessageBoxButtons.YesNoCancel)
Case Windows.Forms.DialogResult.Yes
If System.IO.Directory.Exists(destinationFolderPath) Then
System.IO.Directory.Delete(destinationFolderPath)
My.Computer.FileSystem.CopyDirectory(originalFolderPath, destinationFolderPath)
End If
Case Windows.Forms.DialogResult.No
My.Computer.FileSystem.CopyDirectory(originalFolderPath, nextAvialableFolderPath)
Case Windows.Forms.DialogResult.Cancel
End Select
Else
My.Computer.FileSystem.CopyDirectory(originalFolderPath, destinationFolderPath)
End If
End If
and this is function
VB.NET:
Private Function GetDestinationFolderPath(location As String, folderName As String)
Dim counter As Integer = 0
Dim desiredFolderPath As String = System.IO.Path.Combine(location, String.Format("{0}", folderName))
While System.IO.Directory.Exists(desiredFolderPath)
counter += 1
desiredFolderPath = System.IO.Path.Combine(location, String.Format("{0} ({1})", folderName, counter.ToString))
End While
Return desiredFolderPath
End Function