[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

What VB code will do this kind of rotation of files?

Folder "songs" contains 50 mp3 files.
It also contains a text file of all of the songs in the "songs" folder.

Folder "ready" contains nothing at the moment.

When I press a button:
I need VB code that will look at the text file in "songs" and take the first 4 songs in the list, and copy the associated files to folder "ready".
Next time I press the "button", the NEXT 4 songs from the text file in "songs" is put into folder "ready" and REPLACE the ones that were there.
This continues until all of the songs are used from folder "songs", then it starts again from the top.
If the code rotates the text file to reflect the used files moving to the bottom that's ok.
Can someone show me the code that will do this?
1 Solution
Try this -
Private Sub Copy_Songs()
On Error GoTo ErrHand

Dim sSongsDir As String
Dim sTextFile As String
Dim sReadyDir As String
Dim FString As String
Dim lCtr As Long
Dim iFileCopied As Integer
Dim blnFound As Boolean
blnFound = False
lCtr = 1
iFileCopied = 0
sSongsDir = "C:\Songs"
sTextFile = sSongsDir & "\Text.txt" 'Songs Text File
sReadyDir = sSongsDir & "\Ready" 'Ready Dir

Open sTextFile For Input As #1 'Open Text File
    Do While Not EOF(1)   ' Loop until end of file.
        Input #1, FString ' Read data
        If blnFound = False And CLng(GetSetting("MP3Songs", "List", "Current", 1)) = lCtr Then 'Get Next file from registry
            FileSystem.Kill (sReadyDir & "\*.*") 'Delete previous songs from "Ready"
            blnFound = True
        End If
        If blnFound Then
            If iFileCopied < 4 Then 'Copy 4 songs
                FileSystem.FileCopy sSongsDir & "\" & Trim(FString), sReadyDir & "\" & Trim(FString) 'Copy Songs
                iFileCopied = iFileCopied + 1
                SaveSetting "MP3Songs", "List", "Current", lCtr 'Save Next File in Registry
                Exit Do
            End If
        End If
        lCtr = lCtr + 1
    If EOF(1) = True Then 'Copied every files from Text File
        MsgBox "All Songs in Text File Copied"
        SaveSetting "MP3Songs", "List", "Current", 1 'Save Next File as 1st File
        MsgBox "Copied 4 Songs"
    End If
Close #1

Exit Sub

rbendAuthor Commented:
good thanks

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now