开发者

windows shell - how to detect the current location where script file is placed?

I am trying the windows shell file which will be inserted in the folder where it will analyze folders content.

Now i would like to know how can i detect which is the current path ? i.e. location where the vbs file is placed using开发者_运维问答 FileSystemObject?

Set objFSO = CreateObject("Scripting.FileSystemObject")


Set objFS = CreateObject("Scripting.FileSystemObject")
WScript.Echo objFS.GetParentFolderName(WScript.ScriptFullName)


You can get that from WScript.ScriptFullName. Just remove the filename from the end (the bit after the last backslash). I normally use JScript for scripts, but IIRC VBScript has an InStrRev function that will help you find the last backslash. Or: Create a File object for the WScript.ScriptFullName path and then use its ParentFolder property. Something like (untested):

Dim objFSO
Dim objFile
Dim objFolder

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(WScript.ScriptFullName)
Set objFolder = objFile.ParentFolder


To get the full path only without the extension I use Replace(WScript.ScriptFullName, WScript.ScriptName, "") to just result in a filepath

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜