![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-04 16:26 |
48,038 topics / 350,123 posts / today 0 new / 48,251 members |
| DOS批处理 & 脚本技术(批处理室) » [Help] Small issue about VBS script ([Newbie], Making M3U Playlists) |
| Printable Version 2,428 / 17 |
| Floor1 kich | Posted 2007-01-30 08:44 |
| 中级用户 Posts 168 Credits 397 | |
|
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) |
|
| Floor2 jmz573515 | Posted 2007-01-30 12:54 |
| 银牌会员 Posts 464 Credits 1,212 | |
|
Post an example of an M3U playlist.
|
|
| Floor3 baomaboy | Posted 2007-01-31 10:55 |
| 银牌会员 Posts 554 Credits 1,513 | |
|
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 ] |
|
| Floor4 kich | Posted 2007-01-31 11:50 |
| 中级用户 Posts 168 Credits 397 | |
|
Example of m3u playlist:
====00.Playlist.m3u====== 01.happy.mp3 02.fuun.mp3 03.ff.jj.mp3 uukkll.wma hello.mp3 |
|
| Floor5 kich | Posted 2007-01-31 11:56 |
| 中级用户 Posts 168 Credits 397 | |
|
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! |
|
| Floor6 baomaboy | Posted 2007-01-31 14:29 |
| 银牌会员 Posts 554 Credits 1,513 | |
|
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. |
|
| Floor7 baomaboy | Posted 2007-01-31 14:42 |
| 银牌会员 Posts 554 Credits 1,513 | |
|
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) |
|
| Floor8 kich | Posted 2007-01-31 17:54 |
| 中级用户 Posts 168 Credits 397 | |
|
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 ] |
|
| Floor9 kich | Posted 2007-01-31 18:18 |
| 中级用户 Posts 168 Credits 397 | |
|
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 |
|
| Floor10 kich | Posted 2007-01-31 18:48 |
| 中级用户 Posts 168 Credits 397 | |
|
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) |
|
| Floor11 kich | Posted 2007-01-31 19:11 |
| 中级用户 Posts 168 Credits 397 | |
|
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 =================================== |
|
| Floor12 baomaboy | Posted 2007-02-01 02:33 |
| 银牌会员 Posts 554 Credits 1,513 | |
|
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! |
|
| Floor13 wedd | Posted 2007-02-06 15:37 |
| 初级用户 Posts 16 Credits 36 | |
|
I think batch processing is more convenient.
dir /s/b d:\mp3\*.mp3 >d:\mp3.m3u Just this one command is enough. |
|
| Floor14 112183883 | Posted 2007-02-06 16:14 |
| 初级用户 Posts 31 Credits 128 | |
|
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 ] |
|
| Floor15 ding520 | Posted 2007-02-17 03:41 |
| 初级用户 Posts 15 Credits 29 | |
|
One is stronger than the next! !F lo!
|
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |