vbs获取路径下vba获取文件夹路径和子文件名称

window上边想批量操作文件还是vbs方便
以后不常用window了 下边记录一个vbs拷贝文件的代码 方便以后使用
set fso = createobject(&scripting.filesystemobject&)
set shell = createobject(&wscript.shell&)
set dir = fso.getfolder(&.\jpg\&)
set dir1 = fso.getfolder(&.\obj\&)
dim dir3 : dir3 = &.\model\&
for each fj in dir1.files
objname = fj.name
objname = cstr(objname)
if len(objname) & 4 and right(objname, 4) = &.obj& then
objname = left(objname, len(objname)-4)
for each fi in dir.files
jpgname = fi.name
jpgname = cstr(jpgname)
if len(jpgname) & 4 and right(jpgname, 4) = &.jpg& then
jpgname = left(jpgname, len(jpgname)-4)
if jpgname = objname then
'msgBox jpgname+&===&+objname
fso.MoveFile fj.path, dir3+fj.name
fso.moveFile fi.path, dir3+fi.name
msgbox &ok&
版权声明:本文为博主原创文章,未经博主允许不得转载。
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:49218次
排名:千里之外
原创:23篇
评论:20条
(1)(1)(1)(3)(4)(5)(1)(1)(3)(3)(2)(1)(1)用VBS 获得文件夹下所有文件名,扩展名,不要用批处理,谢了_百度知道
用VBS 获得文件夹下所有文件名,扩展名,不要用批处理,谢了
佳答案 - 由投票者 01:16:31选 面别写!前写,仿照换光vbs写!惜代码知道放!记像比面要简单用VB函数Dir实现递归搜索目录期: 源: 作者:我久前实现.没采用任何控件形式.没调用系统API函数FindFirst,FindNext进行递归调用,别点同我用VBDir()函数.事实,直接采用Dir()函数能进行自身递归调用,我采用种办Dir前搜索目录目录给保存,自身search(strPathName)递归函数依进行递归调用,指定目录搜索完毕.具体代码:''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''函数GetExtName'功能:文件缀名(扩展名)'输入:文件名'输:文件缀名(扩展名)'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Public Function GetExtName(strFileName As String) As StringDim strTmp As StringDim strByte As StringDim i As LongFor i = Len(strFileName) To 1 Step -1strByte = Mid(strFileName, i, 1)If strByte && &.& ThenstrTmp = strByte + strTmpElseExit ForEnd IfNext iGetExtName = strTmpEnd FunctionPublic Function search(ByVal strPath As String, Optional strSearch As String = &&) As BooleanDim strFileDir() As StringDim strFile As StringDim i As LongDim lDirCount As LongOn Error GoTo MyErrIf Right(strPath, 1) && &\& Then strPath = strPath + &\&strFile = Dir(strPath, vbDirectory Or vbHidden Or vbNormal Or vbReadOnly)While strFile && && '搜索前目录DoEventsIf (GetAttr(strPath + strFile) And vbDirectory) = vbDirectory Then '找目录&br& If strFile && &.& And strFile && &..& Then '排除掉父目录(..)前目录(.)lDirCount = lDirCount + 1 '目录数增1ReDim Preserve strFileDir(lDirCount) As StringstrFileDir(lDirCount - 1) = strFile '用态数组保存前目录名End IfElseIf strSearch = && ThenForm1.List1.AddItem strPath + strFileElseIf LCase(GetExtName(strPath + strFile)) = LCase(GetExtName(strSearch)) Then'满足搜索条件则处理该文件Form1.List1.AddItem strPath + strFile '文件全名保存至列表框List1End IfEnd IfstrFile = DirWendFor i = 0 To lDirCount - 1Form1.Label3.Caption = strPath + strFileDir(i)Call search(strPath + strFileDir(i), strSearch) '递归搜索目录NextReDim strFileDir(0) '态数组清空search = True '搜索功Exit FunctionMyErr:search = False '搜索失败End Function
其他类似问题
为您推荐:
扩展名的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁用心创造滤镜
扫码下载App
汇聚2000万达人的兴趣社区下载即送20张免费照片冲印
扫码下载App
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
一个男人!
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(1964)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_086',
blogTitle:'VBS获取文件夹下的所有文件名称。',
blogAbstract:'&& && \'创建一个FileSystemObject对象的事例& && Set&& MyFileObject=CreateObject(\"Scripting.FileSystemObject\")& && \'创建一个Folder对象& && Set&& MyFolder=MyFileObject.GetFolder(\"D:\\test_rar\")\'其中D:\\122改为你所要显示文件夹的名字& && \'循环显示其中文件& && dim&& count& && count=0&& \'计算文件个数& && For&& Each&& thing&& in&& MyFolder.Files& && \'Response.Write(\"&p&\"&thing) &',
blogTag:'软件',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:0,
publishTime:8,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'一个男人!',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}文件和文件夹VBS脚本大全_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
文件和文件夹VBS脚本大全
上传于||文档简介
&&文​件​和​文​件​夹​V​B​S​脚​本​大​全
大小:15.97KB
登录百度文库,专享文档复制特权,财富值每天免费拿!
你可能喜欢您的举报已经提交成功,我们将尽快处理,谢谢!
大家还关注
(window.slotbydup=window.slotbydup || []).push({
id: '2081942',
container: s,
size: '1000,60',
display: 'inlay-fix'}

我要回帖

更多关于 vbs获取当前路径 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信