vba打开指定路径文件夹多个文件夹,VBS通过shell.Application获取的Windows.LocationURL路径,如何判断哪个是最后工作路径?


展开全部  -- PD  答:  您好,PD。您知道,对于脚本专家,此问题(同我们所收到的许多问题一样)被我们归到了“为什么我们没有想到”类别之下。脚本专家将花费大量的时间测试脚本,包括由 Windows 脚本编写社区成员所提交的脚本。(嗯,将会有一位脚本专家花费大量时间测试众多脚本。请注意,即使他必须做这里几乎所有的工作,他也不会抱怨。[编者注:包括大多数抱怨。])其中的许多脚本将向某个文件夹添加文件或从该文件夹删除文件,或者将信息写入该文件夹中的日志文件(该脚本本身就在该文件夹中)。这意味着我们经常需要使用 Windows 资源管理器打开脚本的主文件夹。我们如何打开该文件夹呢?嗯,双击我的电脑、双击 C:、双击 Scripts 等等。我们从来没有想过使用脚本来为我们打开文件夹。
  Set objShell = CreateObject("Wscript.Shell")
  strPath = Wscript.ScriptFullName
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFile = objFSO.GetFile(strPath)
  strFolder = objFSO.GetParentFolderName(objFile)
  strPath = "explorer.exe /e," & strFolder
  objShell.Run strPath
  正如您所看到的,这个脚本不是特别复杂。首先创建一个 Wscript.Shell 对象的实例;稍后会使用这个对象启动 Windows 资源管理器。然后使用下面这行代码获取运行脚本的完整路径(例如 C:\Scripts\My_script.vbs):
  strPath = Wscript.ScriptFullName
  进行下一步之前,要马上澄清一下。有些人可能想知道我们为什么不使用 CurrentDirectory 属性来确定脚本的当前目录。本来可以,但有一个问题:脚本的当前目录与其运行时所在的文件夹不一定相同。毕竟,您可以轻松地启动 C:\Scripts 中的一个脚本,然后将当前目录更改为 C:\Test。对于此专栏,我们需要脚本所驻留的文件夹的名称。如果您更愿意获取当前目录,则请使用下面的这个脚本:
  Set objShell = CreateObject("Wscript.Shell")
  strPath = objShell.CurrentDirectory
  strPath = "explorer.exe /e," & strPath
  objShell.Run strPath
  现在,回到我们的原始脚本。将脚本的完整路径存储到变量 strPath 中之后,我们会创建 Scripting.FileSystemObject 的实例。接下来我们将使用以下两行代码:
  Set objFile = objFSO.GetFile(strPath)
  strFolder = objFSO.GetParentFolderName(objFile)
  此时,我们已拥有此脚本文件本身的路径:C:\Scripts\My_script.vbs。很好,但我们真正需要的是去掉文件名而仅保留文件夹路径:C:\Scripts。尽管有几种不同的方法可以达到此目的,但是我们认为下面的方法最为简单。此时我们所要做的是使用 GetFile 方法绑定到文件 C:\Scripts\My_script.vbs(请注意我们是如何将变量 strPath 作为单独的参数传递给 GetFile 的)。连接到该文件之后,我们便可以使用 GetParentFolderName 方法获取文件所驻留的文件夹的完整路径;不用说,它恰好是 C:\Scripts。这也恰好是我们想要打开的那个文件夹。
  剩下的就很容易了。在将脚本文件夹路径安全地放到变量 strPath 中之后,我们便可使用下面这行代码来构造一个命令行字符串,该字符串将打开 Windows 资源管理器窗口(该窗口的焦点设置为 C:\Scripts):
  strPath = "explorer.exe /e," & strPath  现在,剩余的全部工作就是调用 Run 方法,以传递我们刚刚构造的命令行字符串:
本回答由提问者推荐已赞过已踩过你对这个回答的评价是?评论
收起',getTip:function(t,e){return t.renderTip(e.getAttribute(t.triangularSign),e.getAttribute("jubao"))},getILeft:function(t,e){return t.left+e.offsetWidth/2-e.tip.offsetWidth/2},getSHtml:function(t,e,n){return t.tpl.replace(/\{\{#href\}\}/g,e).replace(/\{\{#jubao\}\}/g,n)}},baobiao:{triangularSign:"data-baobiao",tpl:'{{#baobiao_text}}',getTip:function(t,e){return t.renderTip(e.getAttribute(t.triangularSign))},getILeft:function(t,e){return t.left-21},getSHtml:function(t,e,n){return t.tpl.replace(/\{\{#baobiao_text\}\}/g,e)}}};function l(t){return this.type=t.type
"defaultTip",this.objTip=u[this.type],this.containerId="c-tips-container",this.advertContainerClass=t.adSelector,this.triangularSign=this.objTip.triangularSign,this.delaySeconds=200,this.adventContainer="",this.triangulars=[],this.motherContainer=a("div"),this.oTipContainer=i(this.containerId),this.tip="",this.tpl=this.objTip.tpl,this.init()}l.prototype={constructor:l,arrInit:function(){for(var t=0;t0}});else{var t=window.document;n.prototype.THROTTLE_TIMEOUT=100,n.prototype.POLL_INTERVAL=null,n.prototype.USE_MUTATION_OBSERVER=!0,n.prototype.observe=function(t){if(!this._observationTargets.some((function(e){return e.element==t}))){if(!t
1!=t.nodeType)throw new Error("target must be an Element");this._registerInstance(),this._observationTargets.push({element:t,entry:null}),this._monitorIntersections(),this._checkForIntersections()}},n.prototype.unobserve=function(t){this._observationTargets=this._observationTargets.filter((function(e){return e.element!=t})),this._observationTargets.length
(this._unmonitorIntersections(),this._unregisterInstance())},n.prototype.disconnect=function(){this._observationTargets=[],this._unmonitorIntersections(),this._unregisterInstance()},n.prototype.takeRecords=function(){var t=this._queuedEntries.slice();return this._queuedEntries=[],t},n.prototype._initThresholds=function(t){var e=t
[0];return Array.isArray(e)
(e=[e]),e.sort().filter((function(t,e,n){if("number"!=typeof t
isNaN(t)
t1)throw new Error("threshold must be a number between 0 and 1 inclusively");return t!==n[e-1]}))},n.prototype._parseRootMargin=function(t){var e=(t
"0px").split(/\s+/).map((function(t){var e=/^(-?\d*\.?\d+)(px|%)$/.exec(t);if(!e)throw new Error("rootMargin must be specified in pixels or percent");return{value:parseFloat(e[1]),unit:e[2]}}));return e[1]=e[1]
e[0],e[2]=e[2]
e[0],e[3]=e[3]
e[1],e},n.prototype._monitorIntersections=function(){this._monitoringIntersections
(this._monitoringIntersections=!0,this.POLL_INTERVAL?this._monitoringInterval=setInterval(this._checkForIntersections,this.POLL_INTERVAL):(r(window,"resize",this._checkForIntersections,!0),r(t,"scroll",this._checkForIntersections,!0),this.USE_MUTATION_OBSERVER&&"MutationObserver"in window&&(this._domObserver=new MutationObserver(this._checkForIntersections),this._domObserver.observe(t,{attributes:!0,childList:!0,characterData:!0,subtree:!0}))))},n.prototype._unmonitorIntersections=function(){this._monitoringIntersections&&(this._monitoringIntersections=!1,clearInterval(this._monitoringInterval),this._monitoringInterval=null,i(window,"resize",this._checkForIntersections,!0),i(t,"scroll",this._checkForIntersections,!0),this._domObserver&&(this._domObserver.disconnect(),this._domObserver=null))},n.prototype._checkForIntersections=function(){var t=this._rootIsInDom(),n=t?this._getRootRect():{top:0,bottom:0,left:0,right:0,width:0,height:0};this._observationTargets.forEach((function(r){var i=r.element,a=o(i),c=this._rootContainsTarget(i),s=r.entry,u=t&&c&&this._computeTargetAndRootIntersection(i,n),l=r.entry=new e({time:window.performance&&performance.now&&performance.now(),target:i,boundingClientRect:a,rootBounds:n,intersectionRect:u});s?t&&c?this._hasCrossedThreshold(s,l)&&this._queuedEntries.push(l):s&&s.isIntersecting&&this._queuedEntries.push(l):this._queuedEntries.push(l)}),this),this._queuedEntries.length&&this._callback(this.takeRecords(),this)},n.prototype._computeTargetAndRootIntersection=function(e,n){if("none"!=window.getComputedStyle(e).display){for(var r,i,a,s,u,l,f,h,p=o(e),d=c(e),v=!1;!v;){var g=null,m=1==d.nodeType?window.getComputedStyle(d):{};if("none"==m.display)return;if(d==this.root
d==t?(v=!0,g=n):d!=t.body&&d!=t.documentElement&&"visible"!=m.overflow&&(g=o(d)),g&&(r=g,i=p,a=void 0,s=void 0,u=void 0,l=void 0,f=void 0,h=void 0,a=Math.max(r.top,i.top),s=Math.min(r.bottom,i.bottom),u=Math.max(r.left,i.left),l=Math.min(r.right,i.right),h=s-a,!(p=(f=l-u)>=0&&h>=0&&{top:a,bottom:s,left:u,right:l,width:f,height:h})))break;d=c(d)}return p}},n.prototype._getRootRect=function(){var e;if(this.root)e=o(this.root);else{var n=t.documentElement,r=t.body;e={top:0,left:0,right:n.clientWidth
r.clientWidth,width:n.clientWidth
r.clientWidth,bottom:n.clientHeight
r.clientHeight,height:n.clientHeight
r.clientHeight}}return this._expandRectByRootMargin(e)},n.prototype._expandRectByRootMargin=function(t){var e=this._rootMarginValues.map((function(e,n){return"px"==e.unit?e.value:e.value*(n%2?t.width:t.height)/100})),n={top:t.top-e[0],right:t.right+e[1],bottom:t.bottom+e[2],left:t.left-e[3]};return n.width=n.right-n.left,n.height=n.bottom-n.top,n},n.prototype._hasCrossedThreshold=function(t,e){var n=t&&t.isIntersecting?t.intersectionRatio
0:-1,r=e.isIntersecting?e.intersectionRatio
0:-1;if(n!==r)for(var i=0;i0&&function(t,e,n,r){var i=document.getElementsByClassName(t);if(i.length>0)for(var o=0;o推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
为你推荐:
下载百度知道APP,抢鲜体验使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。扫描二维码下载
×个人、企业类侵权投诉
违法有害信息,请在下方选择后提交
类别色情低俗
涉嫌违法犯罪
时政信息不实
垃圾广告
低质灌水
我们会通过消息、邮箱等方式尽快将举报结果通知您。说明
做任务开宝箱累计完成0
个任务
10任务
50任务
100任务
200任务
任务列表加载中...
}

我要回帖

更多关于 vba打开指定路径文件夹 的文章

更多推荐

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

点击添加站长微信