China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-04 17:22
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Small issue about VBS script ([Newbie], Making M3U Playlists) View 2,434 Replies 17
Original Poster Posted 2007-01-30 08:44 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 397
Posts 168
Joined 2006-10-08 10:07
19-year member
UID 64934
Status Offline
Heroes, I'm a newbie.

VBS

Coding purpose: Create an M3U playlist file in the original directory for all music files (MP3 + WMA) under a certain folder. Here is the code, but there are errors. Can you tell me why?

'======== Get MP3 or WMA Playlist.vbs ======
Dim fso, s, folder,
'Create connection and get the current folder directory of the script
Set fso = createobject("scripting.filesystemobject")
folder = Left(Wscript.ScriptFullName, len(Wscript.ScriptFullName) - len(Wscript.ScriptName))

'Call procedure to output information
SeekLastFolder folder

Set folder = Nothing
Set fso = Nothing


Sub SeekLastFolder (ByVal thePath)
Set fso = CreateObject("scripting.filesystemobject")

'Why does it always prompt an error below, saying the path is not found. I don't understand where the mistake is. Please give me some advice!
Set curFolder = fso.getfolder(thePath)


'Judge if there are files
If curFolder.Files.count > 0 Then
For Each Mefile In curFolder.Files
'Judge if the file is a music file
If Right(Mefile.name, 3) = "mp3" Or Right(Mefile.name, 3) = "wma" Then
'Call function to make Winnamp list
Makem3u(Mefile.name)
End If
Next
End If

'Judge if there are subfolders in the folder
If curFolder.SubFolders.count > 0 Then
For Each Subfolder In curFolder.SubFolders
'Enter subfolder
NewFolder = curfolder & Subfolder
SeekLastFolder NewFolder
Next
End If
End Sub

'Make list
Function Makem3u(MeFileName)
Set Wm3u = fso.CreateTextFile (curFolder & "\" & "00.PlayList.m3u")
s = s & MeFilename & VbCrLf
Wm3u.WriteLine s
Wm3u.Close
Set Wm3u = Nothing
End Function

'=========== End ===================================

The file list to be generated:

====== 00.PlayList.m3u ======
101.Enter Sandman.mp3
102.Creeping Death.mp3
103.Harvester of Sorrow.mp3
104.Welcome Home (Sanitarium).mp3
105.Sad but True.mp3
.
.
.
.
110.Ain't my B_tch.mp3
========== end =======

The numbers are all song names!!

Paste another "Search Files with VBS Script.vbs" file, which can run online.
My above script has a lot in common with this file script, basically the same!
But why can his run and mine can't?
I basically followed his code!!!

[ Last edited by kich on 2007-1-31 at 12:18 PM ]
Attachments
用VBS脚本搜索文件.rar (877 bytes, Credits to download 1 pts, Downloads: 23)
Floor 2 Posted 2007-01-30 12:54 ·  中国 辽宁 本溪 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
Post an example of an M3U playlist.
Floor 3 Posted 2007-01-31 10:55 ·  中国 河北 保定 联通
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
I tried it and found that:
① There is no mistake in the errors described by the original poster. There is an extra comma at the end of the sentence "Dim fso,s,folder," when running the test.
② Remove the above comma to run, but the generated list file is not in the position you want (because curFolder is a sub - procedure variable, and the Function Makem3u cannot be used directly, so the path error is caused. When the path of fso.CreateTextFile is wrong, the system will default to create the file in the root directory).
③ Directly replace the content in sub into the global "SeekLastFolder folder" sentence.
Maybe my understanding is also wrong. I hope the experts can correct it.
[ Last edited by baomaboy on 2007-1-31 at 10:59 AM ]
Floor 4 Posted 2007-01-31 11:50 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 397
Posts 168
Joined 2006-10-08 10:07
19-year member
UID 64934
Status Offline
Example of m3u playlist:
====00.Playlist.m3u======
01.happy.mp3
02.fuun.mp3
03.ff.jj.mp3
uukkll.wma
hello.mp3
Floor 5 Posted 2007-01-31 11:56 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 397
Posts 168
Joined 2006-10-08 10:07
19-year member
UID 64934
Status Offline
Thanks to the person on the 3rd floor, but there are still questions:
① After removing the ",", it still cannot run, saying that the path is not found.
② The sub cannot be separated out alone, because in my SUB, it also uses the SUB of this program. The purpose is that if there are still folders under the folder, then call the SUB program again to enter the sub -folder.
The purpose is to enter all sub -folders!
Floor 6 Posted 2007-01-31 14:29 ·  中国 河北 保定 联通
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
Hehe, I helped you take a look again.

① "Then continue to call the SUB program" should be that this process went wrong. Actually, when the program starts running normally, the sentence Set curFolder = fso.getfolder(thePath) has passed. The error we see is actually the error when you re - call the sub for getting subdirectories.
NewFolder=curfolder&Subfolder'''This sentence is an invalid path, and it will naturally go wrong below.
SeekLastFolder NewFolder
It should be changed to:
NewFolder=curFolder&"\"&Subfolder.name
SeekLastFolder NewFolder

② Still the problem of the path in Function Makem3u:
curFolder is invalid from the external process,
And the example of your provided search:
thePath = Trim(thePath)
FormatPath = thePath
If Right(thePath, 1) = "\" Then FormatPath = Mid(thePath, 1, Len(thePath) - 1) is taken from inside the function.
Floor 7 Posted 2007-01-31 14:42 ·  中国 河北 保定 联通
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
If you only generate one playlist in the current directory, you can directly do this:

Set Wm3u = fso.CreateTextFile ("00.PlayList.m3u")'''Default current path

Or

Set Wm3u = fso.CreateTextFile (folder & "\" & "00.PlayList.m3u")'''Take global variable

If you generate tables in each folder, you can pass two parameters:

Makem3u Mefile.name, curFolder

Function Makem3u(MeFileName, curFolder)
Floor 8 Posted 2007-01-31 17:54 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 397
Posts 168
Joined 2006-10-08 10:07
19-year member
UID 64934
Status Offline
I am very grateful to brother baomaboy for his careful guidance!

Your modification:
NewFolder = curFolder & "\" & Subfolder.name I have tested and it works.

After reading your code, I suddenly realized! After all, a newbie is still a newbie, taking care of one thing, but not the other!

As for the call of the Function function!

In fact, my purpose is to create an M3U file in the subfolder, not to create it in the script directory!

Also, your "curFolder is invalid when taken from an external process" I just realized, this function can only call the parameters in the function parentheses.

Let me ask again, is it that I DIM "curFolder" in the first line!
In this way, the function can be called??

Thank you again!!

[ Last edited by kich on 2007-1-31 at 05:57 PM ]
Floor 9 Posted 2007-01-31 18:18 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 397
Posts 168
Joined 2006-10-08 10:07
19-year member
UID 64934
Status Offline
I tested again, and there's still something wrong with the program in the subfolder!
It still doesn't pass!

PS:
The Function has become two parameters.
Makem3u(Mefile.name)
was written as Makem3u Mefile.name,curfolder

But it still errors in the subfile!
If I add quotes here
NewFolder=curfolder&Subfolder
SeekLastFolder NewFolder

The program doesn't error, but there's no result!
Since adding quotes doesn't error, I think the problem must be here
Floor 10 Posted 2007-01-31 18:48 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 397
Posts 168
Joined 2006-10-08 10:07
19-year member
UID 64934
Status Offline
If the elder brother can understand what I mean!
Hope that you can help me write such a program~
Go and see how you write it!

(If writing, hope the variable names remain unchanged)
Floor 11 Posted 2007-01-31 19:11 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 397
Posts 168
Joined 2006-10-08 10:07
19-year member
UID 64934
Status Offline
Okay, finally okay, after my multiple debugging (really multiple, many times)
Finally, it succeeded, the code changed a bit! The position also changed a bit.
(To facilitate observing the operation process, I set up msgbox tracking display)
Specially write the code as follows and add comments:
(When using, you can remove msgbox! Otherwise, it's very annoying when there are many folders)
'======== Get MP3 or WMA Playlist.vbs ======
Dim fso, s, folder
Set fso = createobject("scripting.filesystemobject")
folder = Left(Wscript.ScriptFullName, len(Wscript.ScriptFullName) - len(Wscript.ScriptName) - 1)
'Here, one more is subtracted, the final "\" is subtracted, which is convenient for adding "\" later in the loop
SeekLastFolder folder
Set folder = Nothing
Set fso = Nothing

''==========================================================================
Sub SeekLastFolder (ByVal thePath)
Set fso = CreateObject("scripting.filesystemobject")
Set curFolder = fso.getfolder(thePath)

If curFolder.Files.count > 0 Then
For Each Mefile In curFolder.Files
If Right(Mefile.name, 3) = "mp3" Or Right(Mefile.name, 3) = "wma" Then
s = s & Mefile.name & vbcrlf
'Here, only the string is set, not directly calling the function, because "For Each Mefile In curFolder.Files" -
'will determine the number of times this is executed. If directly calling the function, it will be executed the number of times of the files.
'Here, only record the playlist file, and finally execute the function!
End If
Next
if s <> "" then
Makem3u s, curfolder
msgbox "ok"
end if
'Originally, there was no this IF statement. Later, I observed that one was also created in the root directory. But there are no music files in my root directory (script directory) ah.
'Later, I thought I knew that the statement "curFolder.Files.count>0" was established, because the script counts as one file!
'But because the FOR loop condition restricts and there is no string output, so it is empty. So an empty playlist file is output. So here an IF condition is added
End If

If curFolder.SubFolders.count > 0 Then
For Each Subfolder In curFolder.SubFolders
msgbox curfolder & "\" & Subfolder.name 'According to the hero's prompt, modified here
SeekLastFolder curfolder & "\" & Subfolder.name

Next
End If
End Sub

''=================================================================================
Function Makem3u(MeFileName, curfolder)
Set Wm3u = fso.CreateTextFile (curfolder & "\" & "00.PlayList.m3u")
Wm3u.WriteLine MeFileName
Wm3u.Close
MeFileName = "" 'If this is not cleared, the playlist will always accumulate, and the last playlist will list all music files
Set Wm3u = Nothing
'Thank you again for baomaboy's guidance, thank you! It succeeded
End Function
'=========== End ===================================
Floor 12 Posted 2007-02-01 02:33 ·  中国 河北 保定 联通
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
I'm really glad to see you're okay...
folder = Left(Wscript.ScriptFullName, len(Wscript.ScriptFullName) - len(Wscript.ScriptName))
Originally, I also found that there was a slight problem with the line to get the directory, but at that time the focus wasn't there, so I didn't mention it. Actually, using the following line should be better
folder=FSO.GetParentFolderName(Wscript.ScriptFullName)
Hehe, hope to progress together!
Floor 13 Posted 2007-02-06 15:37 ·  中国 贵州 贵阳 云岩区 电信
初级用户
Credits 36
Posts 16
Joined 2007-01-02 12:15
19-year member
UID 75265
Gender Male
Status Offline
I think batch processing is more convenient.
dir /s/b d:\mp3\*.mp3 >d:\mp3.m3u
Just this one command is enough.
Floor 14 Posted 2007-02-06 16:14 ·  中国 浙江 杭州 电信
初级用户
Credits 128
Posts 31
Joined 2006-10-23 08:05
19-year member
UID 67855
Gender Male
Status Offline
Bump, heh heh, the brother upstairs is right, it's better to be as simple and convenient as possible.

[ Last edited by 112183883 on 2007-2-6 at 05:16 PM ]
Floor 15 Posted 2007-02-17 03:41 ·  中国 安徽 合肥 电信
初级用户
Credits 29
Posts 15
Joined 2007-02-17 00:05
19-year member
UID 79653
Gender Male
Status Offline
One is stronger than the next! !F lo!
Forum Jump: