有没有办法引用在VBScript中运行的当前文件?我可以使用文件的名称,但它需要可操作,尽管目录更改和重命名.这样做的目的是在文件I/O操作中使用该文件.如果不可能,是否有任何可能的替代方案,例如使文件不可重命名或不可移动?
WScript.ScriptFullName为您提供运行脚本的完整路径.FileSystemObject如果您愿意,可以使用它来进一步解析此路径.例如:
' Assuming the script is at c:\scripts\test.vbs
strFile = WScript.ScriptFullName
With CreateObject("Scripting.FileSystemObject")
MsgBox .GetDriveName(strFile) ' => c:
MsgBox .GetParentFolderName(strFile) ' => c:\scripts
MsgBox .GetFileName(strFile) ' => test.vbs
MsgBox .GetBaseName(strFile) ' => test
MsgBox .GetExtensionName(strFile) ' => vbs
End With
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
645 次 |
| 最近记录: |