VBS怎么获取指定目录下的文件列表
VBS肿么获取某目录下的文件列表
dimFileName,fs,foldername
foldername=InputBox("请输入想要在哪个文件夹查找","VBS查找文件")
Iffoldername=""Then
wscript.quit
EndIf
Setfs=CreateObject("scripting.filesystemobject")
digui(foldername)'调用递归函数进行查找
msgboxFileName'结果显示
'下面是递归查找函数
Functiondigui(path)
Setfolder=fs.getfolder(path)
Setsubfolders=folder.subfolders
SetFiles=folder.Files
ForEachiInFiles
FileName=FileName&i.path&vbNewLine'找到则追加到变量FileName中
Next
ForEachjInsubfolders
digui(j.path)'递归查找子目录
Next
EndFunction
'目录列表与上述相似,稍加修改即可。
vbs获取目录下的文件和文件夹集合
DimsFolder,sExt,message
sFolder="F:\Programming\Applications\VBScript"
Dimfs,oFolder,oFiles,oSubFolders
setfs=CreateObject("Scripting.FileSystemObject")
setoFolder=fs.GetFolder(sFolder)'获取文件夹
setoSubFolders=oFolder.SubFolders'获取子目录集合
foreachfolderinoSubFolders
message="文件夹:"&folder
MsgBoxmessage
Next
setoFiles=oFolder.Files'获取文件集合
foreachfileinoFiles
sExt=fs.GetExtensionName(file)'获取文件扩展名
sExt=LCase(sExt)'转换成小写
message="文件名:"&file.Name&",扩展名:"&sExt'获得文件名(含扩展名,不含路径)和扩展名
MsgBoxmessage
Next
充,上面的folder.Name可以得到文件夹的名称(不含路径)
如:folder=F:\Programming\Applications\VBScript\dd
通过folder.Name可以得到"dd"
批量统计子目录文件数量
@echooff&setlocalenabledelayedexpansion
cd.>dirfiles.txt
for/d%%ain(*.*)do(
setn=0
for/f%%Bin('dir/a-d/b/s"%%a"')doset/an+=1
echo%%a!n!>>dirfiles.txt
)
具体的大家可以凑凑