現場で活躍しそうなVBS
Part1 ファイルパス、ファイルネーム編
実務なので少し役に立ちそうなのでメモ
現場では見れないブログが多いので有益なブログに記載されているコードを
引用しております。
win10 ファイル絶対パスをクリップボードへコピー
Set WshShell = Wscript.CreateObject("WScript.Shell")
Set Fso = Wscript.CreateObject("Scripting.FileSystemObject")
strTemp = WshShell.ExpandEnvironmentStrings("%temp%")
strPath = strTemp & "\__clipCommand.tmp"
Set objHandle = Fso.OpenTextFile( strPath, 2, True )
objHandle.Write Wscript.Arguments(0)
Set WshShell = Wscript.CreateObject("WScript.Shell")
Call WshShell.Run( "cmd.exe /c clip < """ & strPath & """", 0, True )
win10 ファイルネームをクリップボードへコピー
Set WshShell = Wscript.CreateObject("WScript.Shell")
Set Fso = Wscript.CreateObject("Scripting.FileSystemObject")
strTemp = WshShell.ExpandEnvironmentStrings("%temp%")
strPath = strTemp & "\__clipCommand.tmp"
Set objHandle = Fso.OpenTextFile( strPath, 2, True )
strName = Wscript.Arguments(0)
aPath = Split(strName,"\")
strName = aPath(Ubound(aPath))
objHandle.Write strName
Set WshShell = Wscript.CreateObject("WScript.Shell")
Call WshShell.Run( "cmd.exe /c clip < """ & strPath & """", 0, True )
win10 複数のファイルパスをクリップボードへコピー
Set Fso = Wscript.CreateObject("Scripting.FileSystemObject")
str = ""
For I = 0 to Wscript.Arguments.Count-1
aData = Split( Wscript.Arguments(I), "\" )
str = str & aData(Ubound(aData)) & vbCrLf
Next
strTemp = WshShell.ExpandEnvironmentStrings("%temp%")
strPath = strTemp & "\__clipCommand.tmp"
Set objHandle = Fso.OpenTextFile( strPath, 2, True )
objHandle.Write str
Call WshShell.Run( "cmd.exe /c clip < """ & strPath & """", 0, True )