0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ファイルパスを取得するVBScript

Posted at

VBSにてファイルのフルパスを取得する対応を行ったので備忘録的に。
Windows10にて動作確認しています。
引数に渡したファイルをクリップボードに入れますので、SendToコマンドとして利用するのがよき。
ドライブマウントしているファイルについては、マウント先のパスに変換して取得します。

Dim i, arg, wsh

set arg = WScript.Arguments
set wsh = CreateObject("WScript.Shell")

if arg.count = 0 then wscript.quit

arg = exchangeDrivePath(arg)

if arg = ":::" then
  for i = 0 to 100
    if wsh.appactivate ("argument is as follows") then Exit for
  next
  wsh.sendkeys "^c{ENTER}"

else
  wsh.run "wscript.exe """ & WScript.ScriptFillName & """ :::"
  inputbox "argument is as follows","argument is as follows",arg
end if

Function exchangeDrivePath(path)
  Dim driveName, mountPath, exPath, i
  set WIN = WScript.CreateObject("WScript.Network")
  set oDrives = WIN.EnumNetworkDrives

  exPath = path
  for i = 0 to oDrives.Count -1 step 2
    driveName = oDrives.Item(i)
    mountPath = oDrives.Item(i+1)

    set objRegExp = New RegExp
    objRegExp.Pattern = driveName
    exPath = objRegExp.Replace(exPath, mountPath)
    set objRegExp = Nothing
  next
  exchangeDrivePath = exPath
End Function
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?