VBS肿么获取某目录下的文件列表
dim FileName,fs,foldernamefoldername = InputBox("请输入想要在哪个文件夹查找", "VBS查找文件")If foldername = "" Thenwscript.quitEnd IfSet fs = CreateObject("scripting.filesystemobject")digui (foldername)'调用递归函数进行查找msgbox FileName '结果显示'下面是递归查找函数Function digui(path)Set folder = fs.getfolder(path)Set subfolders = folder.subfoldersSet Files = folder.FilesFor Each i In FilesFileName=FileName & i.path & vbNewLine '找到则追加到变量FileName中NextFor Each j In subfoldersdigui (j.path) '递归查找子目录NextEnd Function
'目录列表与上述相似,稍加修改即可。
vbs获取目录下的文件和文件夹集合
Dim sFolder, sExt, messagesFolder = "F:/Programming/Applications/VBScript" Dim fs, oFolder, oFiles, oSubFoldersset fs = CreateObject("Scripting.FileSystemObject")set oFolder = fs.GetFolder(sFolder) '获取文件夹set oSubFolders = oFolder.SubFolders '获取子目录集合 for each folder in oSubFolders message = "文件夹:" & folder MsgBox messageNext set oFiles = oFolder.Files '获取文件集合for each file in oFiles sExt = fs.GetExtensionName(file) '获取文件扩展名 sExt = LCase(sExt) '转换成小写 message = "文件名:" & file.Name & ", 扩展名:" & sExt '获得文件名(含扩展名,不含路径)和扩展名 MsgBox messageNext
充,上面的folder.Name可以得到文件夹的名称(不含路径)
如:folder = F:/Programming/Applications/VBScript/dd
通过folder.Name可以得到"dd"
批量统计子目录文件数量
@echo off&setlocal enabledelayedexpansioncd.>dirfiles.txtfor /d %%a in (*.*) do (set n=0for /f %%B in ('dir /a-d /b /s "%%a"') do set /a n+=1echo %%a !n! >>dirfiles.txt)
具体的大家可以凑凑
新闻热点
疑难解答