1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| dim Myarr
Myarr=array()
objStartFolder = "d:\Music"
outFile="AleaListe.m3u"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(objStartFolder)
Set objoutFile = objFSO.CreateTextFile(outFile,True)
'----Traitement du Folder principal
Set colFiles = objFolder.Files
For Each objFile in colFiles
t = tri_extension(ObjFolder,objFile)
Next
'----Traitement des sous folder
ShowSubfolders objFSO.GetFolder(objStartFolder)
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
t = tri_extension(objFolder,objFile)
Next
ShowSubFolders Subfolder
Next
End Sub
'--------- Création de l'array selon l'extension
Function tri_extension(objFolder,objFile)
If Right(objFile.Name, 3) = "mp3" Or _
Right(objFile.Name, 3) = "mp2" Or _
Right(objFile.Name, 3) = "wma" Or _
Right(objFile.Name, 3) = "wav" Or _
Right(objFile.Name, 3) = "ogg" Or _
Right(objFile.Name, 3) = "mp4" Or _
Right(objFile.Name, 3) = "flv" Or _
Right(objFile.Name, 3) = "mkv" Or _
Right(objFile.Name, 3) = "wmv" Or _
Right(objFile.Name, 3) = "avi" Or _
Right(objFile.Name, 4) = "flac" Then
ReDim Preserve MyArr(UBound(MyArr) + 1) '-- on augmente la taille de l'array
MyArr(UBound(MyArr)) = objfolder.path&"\"&objFile.Name '-- On ajoute l'élement
End if
End function
Shuffle_and_write(MyArr)
wscript.echo "terminer"
'--------On shuffle l'array et on écrit le fichier de sortie
Function Shuffle_and_write(MyArray())
objoutFile.Write "#EXTM3U" & vbCrLf
Dim I, J, Temp
Randomize
For I = LBound(MyArray) To UBound(MyArray)
J = CLng(((UBound(MyArray) - I) * Rnd) + I)
If I <> J Then
Temp = MyArray(I)
MyArray(I) = MyArray(J)
MyArray(J) = Temp
End If
Next
counta=0
while counta <> Ubound(Myarray)+1
objoutFile.Write myarray(counta) & vbCrLf
counta = counta + 1
wend
objoutFile.Close
End Function |
Partager