'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) '获取文件夹 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 复制代码
'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) '获取文件夹 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