一个vbs文件将指定文件夹下的文件名输出到指定文件夹下

'on error resume Next
Const MY_COMPUTER=&H11&
Const WINDOW_HANDLE=0
Const OPTIONS=0
'设置我的电脑为根目录
Set objShell=CreateObject("Shell.Application")
Set objFolder=objShell.Namespace(MY_COMPUTER)
Set objFolderItem=objFolder.Self
strPath=objFolderItem.Path

fromPath= GetPath(strPath,"选择要列出的文件夹:")
'获取当前文件夹
set fileObj=createobject("Scripting.FileSystemObject")
toFilePath = fileObj.GetFolder(".").Path&"/文件列表.txt"

cmdStr="cmd /c dir "&fromPath&" /s /b >"&toFilePath
Set ws = CreateObject("Wscript.Shell")
Set objWshScriptExec = ws.Exec(cmdStr)
'Msgbox "生成成功"
ws.run toFilePath,0,ture

'获取文件夹
Function GetPath(strPath,title)
Set objShell=CreateObject("Shell.Application")
Set objFolder=objShell.BrowseForFolder(WINDOWS_HANDLE,title,OPTIONS,strPath)
 
If objFolder Is Nothing Then
Wscript.Quit
End If

Set objFolderItem=objFolder.Self
objPath=objFolderItem.Path
If objPath="" Then
Wscript.Quit
Else
GetPath=objPath
End If
End function


拷贝粘贴到文本文件里,保存为vbs文件.

双击运行,试试!

哈哈

posted @ 2013-06-28 16:12  simadi  阅读(1376)  评论(0编辑  收藏  举报