找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 18751|回复: 3

[问题求助] VBS脚本如何用纯粹的字符串处理方式来获取上层文件夹?[已解决]

[复制链接]
发表于 2012-2-3 07:17:39 | 显示全部楼层 |阅读模式
本帖最后由 daols 于 2012-4-26 23:29 编辑

想用纯粹的字符串处理方式来获取上层文件夹...理论上parDir获得的值貌似应该结尾带"\"的, 但是不知道为什么我现在得到的thisDir不带...求合理解释...要求不要取消thisvbs()函数...因为手工输入wscript.scriptfullname很麻烦不美观...还有就是只用字符串处理方法...不用fso...不用正则...

xargs-install.vbs 如下:
  1. Private Function thisvbs()
  2. thisvbs=wscript.scriptfullname
  3. End Function

  4. Private Function parDir(FileOrFolder, delLen)
  5. if delLen="" then : delLen=0 : end if ' "-0" end with ""
  6. FileOrFolder=join(split(FileOrFolder, "/"), "")
  7. if Right(FileOrFolder, 1)="" then : FileOrFolder=Left(FileOrFolder, Len(FileOrFolder)-1) : end if
  8. parDir=Left(FileOrFolder,InstrRev(FileOrFolder,"")-delLen)
  9. End Function

  10. thisDir=parDir(thisvbs(), 0) '这里有问题, 得到的字符串结尾不带"", 但是直接引用wscript.scriptfullname的话就带""
  11. upDir=parDir(thisDir, 0)

  12. msgbox parDir("B:\shellreg\xargs-vbs\xargs-install.vbs", 0)
  13. msgbox thisDir
  14. msgbox parDir(wscript.scriptfullname, 0)
  15. msgbox upDir
  16. msgbox parDir(parDir(wscript.scriptfullname, 0), 0)
复制代码
发表于 2012-2-3 11:51:22 | 显示全部楼层
舍近求远
发表于 2012-2-3 13:33:50 | 显示全部楼层
你检测最后一个字符,看看是否为“\”,如果不是就自动加上~
 楼主| 发表于 2012-4-26 23:26:55 | 显示全部楼层
谢谢楼上两位...
csdn有人告我说是变量声明混乱造成的...已解决
Private Function parDir(FileOrFolder, delLen)
Dim ArgStr : ArgStr=FileOrFolder
if delLen="" then : delLen=0 : end if ' "-0" end with "\"
ArgStr=join(split(ArgStr, "/"), "\")
if Right(ArgStr, 1)="\" then : ArgStr=Left(ArgStr, Len(ArgStr)-1) : end if
parDir=Left(ArgStr,InstrRev(ArgStr,"\")-delLen)
End Function
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 11:25 , Processed in 0.019930 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表