how to copy files to usb-drive in certain order?
how to copy files to usb-drive in certain order?
I have some mp3 files and would like to copy them to a USB-drive in certain order, the reason is that my stereo will sort the files in the order that they were written
all the files start with a three digit number then the song name, like 001 first song, 002 second song and so on
the problem is that copying the files using the Windows explorer by select all the files and then draging them to the USB-drive will copy the files out of order
any suggestions?
all the files start with a three digit number then the song name, like 001 first song, 002 second song and so on
the problem is that copying the files using the Windows explorer by select all the files and then draging them to the USB-drive will copy the files out of order
any suggestions?
Re: how to copy files to usb-drive in certain order?
srvaldez,
I don't clearly understand the problem:
I don't clearly understand the problem:
- Is it related to: "last modified" date/time stamp (aka: programming)?
Is it related to: configuration of File Explorer?
Re: how to copy files to usb-drive in certain order?
the problem is that the stereo sorts the files as it finds them on the USB-drive which is in the order that they were copied
like I said, selecting all the files in Windows explorer and dragging them to the USB-drive will copy the files out of order, that is, unsorted
like I said, selecting all the files in Windows explorer and dragging them to the USB-drive will copy the files out of order, that is, unsorted
Re: how to copy files to usb-drive in certain order?
srvaldez,
in that case you'll have to program your own "custom copy" routine, that:
in that case you'll have to program your own "custom copy" routine, that:
- 1) reads all titles (string array)
2) sorts array (to your preference)
3) copies (one by one) to the target ...
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: how to copy files to usb-drive in certain order?
I had to solve this problem a few years ago. Perhaps you have the same cheap MP3 player?
https://www.amazon.co.uk/gp/aw/cr/rR3AN26S2NR8RXR
You can copy files in alphabetical order through the Windows command line:
https://www.amazon.co.uk/gp/aw/cr/rR3AN26S2NR8RXR
You can copy files in alphabetical order through the Windows command line:
Code: Select all
cd /d "path\to\copy\from"
for /f "usebackq delims=" %i in (`dir /b /on`) do copy "%i" "path\to\copy\to"
Re: how to copy files to usb-drive in certain order?
Here I have created 10 blank files, sorted their titles and moved them to another folder.
Please use this code inside a temp folder to run it.
Then you will easily adapt something similar to your destination path.
Please use this code inside a temp folder to run it.
Then you will easily adapt something similar to your destination path.
Code: Select all
#Include "file.bi"
Sub savefile(filename As String,p As String="")
Dim As Integer n
n=Freefile
If Open (filename For Binary Access Write As #n)=0 Then
Put #n,,p
Close
Else
Print "Unable to save " + filename
End If
End Sub
sub bsort(s() as string)
for n as long=lbound(s) to ubound(s)-1
for m as long=n+1 to ubound(s)
if s(m)<s(n) then swap s(m),s(n)
next
next
end sub
dim as string g(1 to 10)
for n as long=lbound(g) to ubound(g)
g(n)=right("000"+str(n),3)+ "Title"+str(n)+".mp3"
print g(n)
next
bsort(g())
dim as string c=curdir+"\newfiles"
shell "mkdir "+c
for n as long=lbound(g) to ubound(g)
savefile(g(n))
shell "copy " + curdir + "\" + g(n) + " " + c
next
sleep
Re: how to copy files to usb-drive in certain order?
counting_pine and dodicat, thank you
much appreciated :-)
much appreciated :-)
Re: how to copy files to usb-drive in certain order?
Tested pseudocode ;-)
Code: Select all
GetFiles C:\Fotos\Fotos2018\IMG_2018*.jpg ; filenames to string array
SortFiles name ; sort alphabetically
For_ each esi in Files$()
invoke CopyFile, esi, Cat$("J:\Temp\"+Extract$(esi, "\", 0, xsRinstrL)), 0
Next
Re: how to copy files to usb-drive in certain order?
I found that it was hard to navigate through 600+ songs, so inspired by dodicat's code I stitched together this code
the code creates folders starting with 01 and copies 12 songs into each folder, except for the last folder which will hold 12+remainder songs
the same could be accomplished with a batch file
the code creates folders starting with 01 and copies 12 songs into each folder, except for the last folder which will hold 12+remainder songs
Code: Select all
'======================================================
' list files in a folder in a text file in that folder
' by Richard
' https://www.freebasic.net/forum/viewtopic.php?p=191571#p191571
'======================================================
Dim As String folder = "C:\Users\srvaldez\Desktop\MusicToBeCopied"
Dim As String filename, s, q=chr(34)
redim as string g(1 to 1)
dim as long count=1, max, k
filename = Dir( folder & "\*", &h21 )
Do While Len( filename )
Select Case filename
Case "." ' list of file names to ignore
Case ".."
Case Else
ReDim Preserve g(1 to count)
g(count) = filename
count+=1
End Select
filename = Dir( )
Loop
count-=1
max=count\12
k=1
if max>=0 then
shell "mkdir H:\MyMusic"
for i as long=1 to max
s=trim(str(i))
if len(s)<2 then s="0"+s
s="H:\MyMusic\"+s
shell "mkdir "+s
for j as long=k to k+11
shell "copy "+q+folder+"\"+g(j)+q+" "+s
k+=1
next
if max*12<count andalso i=max then
for last as long=k to count
shell "copy "+q+folder+"\"+g(last)+q+" "+s
next
end if
next
end if
Re: how to copy files to usb-drive in certain order?
You could get them all by putting this into your original music folder
(nothing done, only shown)
(nothing done, only shown)
Code: Select all
#Include "file.bi"
Sub string_split(byval s As String,chars As String,result() As String)
redim result(0)
Dim As String var1,var2
Dim As long pst,LC=len(chars)
#macro split(stri)
pst=Instr(stri,chars)
var1="":var2=""
If pst<>0 Then
var1=Mid(stri,1,pst-1)
var2=Mid(stri,pst+LC)
Else
var1=stri
End if
if len(var1) then
redim preserve result(1 to ubound(result)+1)
result(ubound(result))=var1
end if
#endmacro
Do
split(s):s=var2
Loop Until var2=""
End Sub
#Include "file.bi"
Function loadfile(file as string) as String
If FileExists(file)=0 Then Print file;" not found":Sleep:end
var f=freefile
Open file For Binary Access Read As #f
Dim As String text
If Lof(f) > 0 Then
text = String(Lof(f), 0)
Get #f, , text
End If
Close #f
return text
end Function
Sub savefile(filename As String,p As String="")
Dim As Integer n
n=Freefile
If Open (filename For Binary Access Write As #n)=0 Then
Put #n,,p
Close
Else
Print "Unable to save " + filename
End If
End Sub
sub bsort(s() as string)
for n as long=lbound(s) to ubound(s)-1
for m as long=n+1 to ubound(s)
if s(m)<s(n) then swap s(m),s(n)
next
next
end sub
shell "dir /b > zlist.dat"
sleep 10
dim as string s2=loadfile("zlist.dat")
redim as string names()
string_split(s2,chr(10),names())
bsort(names())
for n as long=lbound(names) to ubound(names)
if val(names(n)) then print names(n)
next
for n as long=lbound(names) to ubound(names)
if val(names(n)) then
'copy to your drive
' shell "copy " + curdir + "\" + names(n) + " " + c
end if
next
print "done"
sleep