|
kich
中级用户
  
积分 397
发帖 168
注册 2006-10-8
状态 离线
|
『楼 主』:
[求助]关于VBS脚本的小问题([新手],制作M3U播放列表)
使用 LLM 解释/回答一下
英雄们,我是新手.
VBS
编码目的:把某个文件夹下所有音乐文件(MP3+WMA)在它原目录下创建M3U播放列表文件以下是代码,但有出错,大家告诉我为什么,好吗??
'======== 获得MP3或WMA播放列表.vbs ======
Dim fso,s,folder,
'创建连接,并获得脚本当前文件夹目录
Set fso=createobject("scripting.filesystemobject")
folder = Left(Wscript.ScriptFullName,len(Wscript.ScriptFullName)-len(Wscript.ScriptName))
'调用过程,输出信息
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
'调用函数制作Winnamp列表
Makem3u(Mefile.name)
End If
Next
End If
'判断文件夹里有子文件夹
If curFolder.SubFolders.count > 0 Then
For Each Subfolder In curFolder.SubFolders
'进入子文件夹
NewFolder=curfolder&Subfolder
SeekLastFolder NewFolder
Next
End If
End Sub
'制作列表
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 ===================================
想要生成的文件列表:
====== 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 =======
数字都是歌曲名!!
再帖上一个"用VBS脚本搜索文件.vbs"的文件,是网上的,可以运行.
我的上面脚本和这个文件脚本有很多相似之处,基本上就是一样的!
但为什么它的可以运行,我的就不可以呢?
我基本上就是按照他的代码来的!!!
Last edited by kich on 2007-1-31 at 12:18 PM ]
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 ]
附件
1: 用VBS脚本搜索文件.rar (2007-1-31 12:18, 877 bytes, 下载附件所需积分 1 点
,下载次数: 23)
|
|
2007-1-30 08:44 |
|
|
jmz573515
银牌会员
    
积分 1212
发帖 464
注册 2006-12-13
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
贴一个M3U播放列表表的例子看看
Post an example of an M3U playlist.
|
|
2007-1-30 12:54 |
|
|
baomaboy
银牌会员
    
积分 1513
发帖 554
注册 2005-12-30
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
我试了下发现
①楼主所述错误之处并无错,运行试只有“Dim fso,s,folder,”此句最后多一,号
②将上述,号去掉即可运行,但生成的列表文件不在你希望的位置(因为curFolder 是子过程变量,Function Makem3u无法直接使用所以造成路径错误,当fso.CreateTextFile 的路径出错时系统会默认把文件在创建于根目录)
③将sub中的内容直接替换到全局中的SeekLastFolder folder这句即可。
也许我的理解也有错误,还望高手斧正
Last edited by baomaboy on 2007-1-31 at 10:59 AM ]
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 ]
|
|
2007-1-31 10:55 |
|
|
kich
中级用户
  
积分 397
发帖 168
注册 2006-10-8
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
m3u播放列表例子:
====00.Playlist.m3u======
01.happy.mp3
02.fuun.mp3
03.ff.jj.mp3
uukkll.wma
hello.mp3
Example of m3u playlist:
====00.Playlist.m3u======
01.happy.mp3
02.fuun.mp3
03.ff.jj.mp3
uukkll.wma
hello.mp3
|
|
2007-1-31 11:50 |
|
|
kich
中级用户
  
积分 397
发帖 168
注册 2006-10-8
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
感谢3楼的,不过还有疑问:
①去掉","后,还是不能运行,说找不到路径
②sub 不可以单独提出来吧,因为我SUB里面,又用到SUB本程序,目的是如果文件夹下还有文件夹,那么再接着调用SUB程序,再进入子文件夹.
目的就是进入所有子文件夹!
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!
|
|
2007-1-31 11:56 |
|
|
baomaboy
银牌会员
    
积分 1513
发帖 554
注册 2005-12-30
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
呵呵,又帮你看了下
①“那么再接着调用SUB程序”应该是这个过程出错了,实际上程序开始正常运行时Set curFolder = fso.getfolder(thePath)这句已经通过了,我们看到的错误其实是你那个为取子目录而重新调用sub时出错
NewFolder=curfolder&Subfolder'''此句是无效路径,下面当然出错。
SeekLastFolder NewFolder
应改为:
NewFolder=curFolder&"\"&Subfolder.name
SeekLastFolder NewFolder
②还是Function Makem3u取路径问题:
curFolder取自外部过程无效,
而你提供的搜索的例子:
thePath = Trim(thePath)
FormatPath = thePath
If Right(thePath, 1) = "\" Then FormatPath = Mid(thePath, 1, Len(thePath) - 1) 是取自函数内部。
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.
|
|
2007-1-31 14:29 |
|
|
baomaboy
银牌会员
    
积分 1513
发帖 554
注册 2005-12-30
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
如果你只生成一个播放列表在当前目录下你直接可以这样
Set Wm3u=fso.CreateTextFile (“00.PlayList.m3u")'''默认当前路径
或者
Set Wm3u=fso.CreateTextFile (folder&"\"&"00.PlayList.m3u")'''取全局变量
如果你在每个文件夹下都生成表可以传递两个参数
Makem3u Mefile.name,curFolder
Function Makem3u(MeFileName,curFolder)
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)
|
|
2007-1-31 14:42 |
|
|
kich
中级用户
  
积分 397
发帖 168
注册 2006-10-8
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
很感谢baomaboy兄的悉心指导!
您的修改:
NewFolder=curFolder&"\"&Subfolder.name 我已经测试通过了.
看完你的代码,我才恍然大悟!新手毕竟还是新手,顾得了这头,顾不了那头!
至于Function函数的调用!
其实我的目的就是想在子文件夹下建M3U文件的,并不是想在脚本目录下建!
还有,您的"curFolder取自外部过程无效"我想想,也才明白,这函数只可以调用函数括号里的参数的.
再问一下,是不是把"curFolder"在第一行DIM一下!
这样函数就可以调用了??
再次感谢您!!
Last edited by kich on 2007-1-31 at 05:57 PM ]
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 ]
|
|
2007-1-31 17:54 |
|
|
kich
中级用户
  
积分 397
发帖 168
注册 2006-10-8
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
又测试了下,还是子文件夹这里的程序有点错!
还是这不通过!
PS:
Function已经变做两个参量了.
Makem3u(Mefile.name)
写成了 Makem3u Mefile.name,curfolder
但在子文件里仍然出错!
要是把这里
NewFolder=curfolder&Subfolder
SeekLastFolder NewFolder
加上引号,程序不出错,但也无结果!
既然加了引号不出错,我想应该证明问题就在这了
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
|
|
2007-1-31 18:18 |
|
|
kich
中级用户
  
积分 397
发帖 168
注册 2006-10-8
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
如果大哥能理解我的意思!
希望可以帮我写一个这样的程序~
去看看您是怎么写的!
(如果写的话,希望变量名不要变)
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)
|
|
2007-1-31 18:48 |
|
|
kich
中级用户
  
积分 397
发帖 168
注册 2006-10-8
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
OK了,终于OK了,经过我多次调试(真的是多次,很多次啊)
最后,终于成功了,代码变了一些!位置也变了一些.
(为便于观察操作流程,我设置了 msgbox 跟踪显示)
特将代码写如下,并加注释:
(用的时候,可以把msgbox去掉!否则文件夹多的时候,很烦)
'======== 获得MP3或WMA播放列表.vbs ======
Dim fso,s,folder
Set fso=createobject("scripting.filesystemobject")
folder = Left(Wscript.ScriptFullName,len(Wscript.ScriptFullName)-len(Wscript.ScriptName)-1)
'这里多减了个1,把最后的"\"减掉,方便以后循环加"\"
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
'这里,只是设置了字符串,而不是直接调用函数,因为"For Each Mefile In curFolder.Files"-
'将决定这里执行的次数,如果直接调用函数,讲会执行文件数的次数.
'这里只是记录下列表文件,最后在执行函数!
End If
Next
if s<>"" then
Makem3u s,curfolder
msgbox "ok"
end if
'本来是没有这个IF语句的,后来观察到,在跟目录下也建了一个,而我跟目录下(脚本目录),根本就没有音乐文件啊.
'后来想想知道,"curFolder.Files.count>0"这句语句成立了,因为脚本算一个文件了嘛!
'但因为FOR循环里条件限制,又没字符串输出,所以,是空.这样输出一个空列表文件.所以这里加了个IF条件
End If
If curFolder.SubFolders.count > 0 Then
For Each Subfolder In curFolder.SubFolders
msgbox curfolder&"\"&Subfolder.name '按照英雄提示,修改了这里
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="" '如果这里不清空,列表讲一直累计下去,到最后一个列表,会列出所有音乐文件
Set Wm3u=Nothing
'再次感谢baomaboy的指引,谢谢!成功了
End Function
'=========== End ===================================
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 ===================================
|
|
2007-1-31 19:11 |
|
|
baomaboy
银牌会员
    
积分 1513
发帖 554
注册 2005-12-30
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
看到你ok了真替你高兴......
folder = Left(Wscript.ScriptFullName,len(Wscript.ScriptFullName)-len(Wscript.ScriptName))
最初也发现取目录这句稍有点点问题,不过当时重点不在那里所以没提出来,其实用下面这句应该好一点
folder=FSO.GetParentFolderName(Wscript.ScriptFullName)
呵呵,希望共同进步!
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!
|
|
2007-2-1 02:33 |
|
|
wedd
初级用户
 
积分 36
发帖 16
注册 2007-1-2
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
我觉得用批处理更方便
dir /s/b d:\mp3\*.mp3 >d:\mp3.m3u
只要这一个命令就够了
I think batch processing is more convenient.
dir /s/b d:\mp3\*.mp3 >d:\mp3.m3u
Just this one command is enough.
|
|
2007-2-6 15:37 |
|
|
112183883
初级用户
 
积分 128
发帖 31
注册 2006-10-23
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
顶一下,呵呵,楼上的兄弟说得对,能简便尽量简便一些的好。
Last edited by 112183883 on 2007-2-6 at 05:16 PM ]
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 ]
|
|
2007-2-6 16:14 |
|
|
ding520
初级用户
 
积分 29
发帖 15
注册 2007-2-17
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
一个比一个强 !F咯!
One is stronger than the next! !F lo!
|
|
2007-2-17 03:41 |
|
|