VB Forms Application Current Directory and File Copy Operation

~OSD~ 2,131 Reputation points
2020-12-10T12:47:27.673+00:00

Hi,

I have following directory structure on Windows 10:

46983-image.png

Random User 1 and Random User 2 are directories which represents dynamically created directories names. Whereas the - Backup\Bookmarks\Chrome structure is constant.
Due to this dynamic naming scheme, I have placed VB Forms application inside the user directory and using "AppDomain.CurrentDomain.BaseDirectory" to define "application's current directory"

Need: I would like to copy bookmark file from this above structure to current user profile (C:\Users\%UserName%\Backup\Bookmarks\Chrome\Bookmarks).
Following has been tried in VB but I am getting error "Index out of bound", any ideas?

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click  
        ' Restore Chrome   
        Dim Chrome_curBackupDir As String = AppDomain.CurrentDomain.BaseDirectory & "\Backup\Bookmarks\Chrome"  
        Dim Chrome_dstDir() As String = IO.Directory.GetFiles(IO.Path.Combine("C:\Users", Environment.UserName, "AppData", "Local", "Google", "Chrome", "User Data", "Default"), IO.SearchOption.AllDirectories)  
        System.IO.File.Copy(Chrome_curBackupDir & "\Bookmark", Chrome_dstDir(0), overwrite:=True)  

    End Sub  
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,644 questions
{count} votes

Accepted answer
  1. ~OSD~ 2,131 Reputation points
    2020-12-11T11:44:38.32+00:00

    Hi and thanks for suggestions.

    Now I have a compact version as follows and seems to be working fine, any improvements will be appreciated though.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful