copy mp3 files with specific title

Yeshua

Member
Licensed User
Longtime User
B4X:
Sub Button1_Click
Dim MyList As List
Dim MyFile As String
Dim i As Short
Dim p As Phone
Dim FilePathSource As String          :FilePathSource=File.DirAssets
Dim FilePathDest As String          :FilePathDest=File.DirRootExternal & "/Audio"
    MyList.Initialize                   
    MyList=File.ListFiles(FilePathSource)
    For i=0 To MyList.Size-1
    MyFile=MyList.Get(i)
    If MyFile.Contains("SUN")=True  Then
   Try
   File.MakeDir(File.DirRootExternal, "/Audio")
   'Msgbox
    File.Copy(FilePathSource,MyFile,FilePathDest,MyFile)
    Catch
    End Try
    End If
    Next
End Sub
I have many mp3 files with "SUN" title name.
How do i copy this mp3 files in at once, with this title through using and modifying this code?
Can you help me please? Thanks!:sign0085:
 

Yeshua

Member
Licensed User
Longtime User
I have no errors. I wanted to know how to copy the mp3 files with specific title.
I have hundreds of mp3 files, but I want to copy only those that have the title "SUN".
But in this way does not copy anything.
 

Attachments

  • Title.JPG
    Title.JPG
    24.5 KB · Views: 353
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
This code works and is tested:

B4X:
Sub Button1_Click
   Dim MyList As List : Dim MyFile As String
   Dim FilePathSource = File.DirAssets As String
   Dim FilePathDest = File.DirRootExternal & "/Audio" As String
   File.MakeDir("", FilePathDest)
   MyList = File.ListFiles(FilePathSource)
   For i = 0 To MyList.Size-1
      MyFile = MyList.Get(i)
      If MyFile.ToUpperCase.Contains("SUN") AND File.IsDirectory(FilePathSource, MyFile) = False Then
         File.Copy(FilePathSource, MyFile, FilePathDest, MyFile)
      End If
   Next
End Sub
 
Upvote 0

Yeshua

Member
Licensed User
Longtime User
Hi, margret.
This code works if you remove "toUpperCase" and put ".mp3" instead of "sun."
In this way, however, copy all the mp3 files.
I want to copy only those who have the title "SUN".

I thought of an ID3 "Class Module"

Sub Class_Globals
Public Title As String
End Sub

but I can not develop the code.
Look attached thumbnails.

B4X:
Sub Button1_Click
Dim MyList As List
Dim MyFile As String
Dim i As Short
Dim p As Phone
Dim FilePathSource As String          :FilePathSource=File.DirAssets
Dim FilePathDest As String          :FilePathDest=File.DirRootExternal & "/Audio"


Dim Title As ID3
Title.Title = "SUN"
   
   MyList.Initialize                   
    MyList=File.ListFiles(FilePathSource)
    For i=0 To MyList.Size-1
    MyFile=MyList.Get(i)
    If MyFile.Contains(?????)=True  Then
   Try
   File.MakeDir(File.DirRootExternal, "/Audio")
    File.Copy(FilePathSource,MyFile,FilePathDest,MyFile)
    Catch
    End Try
    End If
    Next
End Sub
:signOops:
 

Attachments

  • Title.JPG
    Title.JPG
    37.1 KB · Views: 356
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
The code Margret posted works.

It looks like you have no files with SUN in the name in your Assets folder.

Just a thought, but when you say "title", do you mean the song title as set with the ID3 tags? Your code (and Margrets) works on the filename not on ID3 tags.
 
Upvote 0

Yeshua

Member
Licensed User
Longtime User
I refer to the title of the album (thumbnails attached). The name of the song is "Spring". I have "Spring" in DirAssets
I want to copy using the title.
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
To repeat myself, if by title you are referring to the title in the ID3 tag, the code will not work, it only works on the filename.

I think there is an ID3 library, use that to identify the songs you wish to copy.
 
Upvote 0

Yeshua

Member
Licensed User
Longtime User
The code Margret posted is ok.

. . . a new question.


How do I copy only the mp3 files that contain the word "Spring"?

B4X:
Sub Button1_Click
    Dim MyList As List : Dim MyFile As String
    Dim FilePathSource = File.DirAssets As String
    Dim FilePathDest = File.DirRootExternal & "/Audio" As String
    File.MakeDir("", FilePathDest)
    MyList = File.ListFiles(FilePathSource)
    For i = 0 To MyList.Size-1
        MyFile = MyList.Get(i)
        If MyFile.ToUpperCase.Contains("Spring") AND File.IsDirectory(FilePathSource, MyFile) = False Then
            File.Copy(FilePathSource, MyFile, FilePathDest, MyFile)
        End If
    Next
End Sub
In this way are copied to all the other mp3 files, too.
:sign0013:
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
This should work:

B4X:
Sub Button1_Click
    Dim MyList As List : Dim MyFile As String
    Dim FilePathSource = File.DirAssets As String
    Dim FilePathDest = File.DirRootExternal & "/Audio" As String
    File.MakeDir("", FilePathDest)
    MyList = File.ListFiles(FilePathSource)
    For i = 0 To MyList.Size-1
        MyFile = MyList.Get(i)
        If MyFile.ToUpperCase.Contains("SPRING") AND MyFile.ToLowerCase.EndsWith(".mp3") AND File.IsDirectory(FilePathSource, MyFile) = False Then
            File.Copy(FilePathSource, MyFile, FilePathDest, MyFile)
        End If
    Next
End Sub
 
Last edited:
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Sorry to correct Margret, but as you have set the filename to upper case, you need SPRING not spring:

B4X:
If MyFile.ToUpperCase.Contains("SPRING") AND MyFile.ToLowerCase.EndsWith(".mp3") AND File.IsDirectory(FilePathSource, MyFile) = False Then
 
Upvote 0
Top