B4J Question Transfer file from Downloads folder to Music folder in internal storage using B4J

Hi,

I am trying to connect my phone to my computer or laptop using a USB cable. Then, I want to use B4J to transfer a file from the Downloads folder in the internal storage of my phone to the Music folder in the internal storage.

I would appreciate it if you could guide me on how I can do this.

Thank you
 
I myself wrote this function in B4J:
B4X:
Private Sub Button1_Click
    
    Copy("C:\Users\Mohsen\Desktop","NewFolder","C:\Users\Mohsen\Desktop","NewFolder2",True)

End Sub

Sub Copy(DirSource As String, FileSource As String, DirTarget As String, FileTarget As String,First As Boolean)
    If File.IsDirectory(DirSource, FileSource) Then
        
        If First Then
            File.MakeDir(File.Combine(DirTarget, FileTarget),FileSource)
        
            DirTarget=File.Combine(DirTarget, FileTarget)
            FileTarget=FileSource
        End If
        
        Dim sourcePath As String = File.Combine(DirSource, FileSource)
        Dim targetPath As String = File.Combine(DirTarget, FileTarget)
        
        Dim sourceFiles As List = File.ListFiles(sourcePath)
        If sourceFiles.IsInitialized = False Then Return 'Return if folder is not accessible
        File.MakeDir(DirTarget, FileTarget)
        For Each name As String In sourceFiles
            If File.IsDirectory(sourcePath, name) Then
                Copy(sourcePath, name, targetPath, name,False)
            Else
                File.Copy(sourcePath, name, targetPath, name)
            End If
        Next
    Else
        File.Copy(DirSource, FileSource, DirTarget, FileTarget)
    End If
End Sub
Now this code works and copies the NewFolder folder into NewFolder2 on the desktop. But I don't know how to identify the phone connected to the computer and do the same operation for it!
 
Upvote 0
Top