エクスプローラで、SHIFT キーを押しながら右クリックすると『パスとしてコピー』がありますが、ダブルクォートが付加されています( たいていはそのほうがいいのですが )ので、ダブルクォートのないパスを取得します▼ こんな感じで取得されます "C:\Program Files\7-Zip\7-zip.dll" filepath.vbs( SendTo ディレクトリに置いてください )
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) Call WshShell.Run( "cmd.exe /c clip < """ & strPath & """", 0, True )
▼ こうなります C:\Program Files\7-Zip\7-zip.dll 以下はディレクトリ部分を省いた名前の部分のみをクリップボードにコピーします。 filename.vbs( SendTo ディレクトリに置いてください )
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 Call WshShell.Run( "cmd.exe /c clip < """ & strPath & """", 0, True )
▼ こうなります 7-zip.dll さらに以下では、複数ファイルを選択した場合のファイル名部分だけを取り出して複数行としてコピーします( 但しあまり大量のファイルは元々の文字列の制限によりエラーとなります filelist.vbs( SendTo ディレクトリに置いてください )
Set WshShell = Wscript.CreateObject("WScript.Shell") 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 )
▼ ファイルが多すぎて起きるエラー▼ うまくいくとこんな感じです nslookup.exe ntdll.dll odbc32.dll ole32.dll 操作補足 エクスプローラで SendTo フォルダに移動するには、アドレスバーに sendto と直接入力します。テンポラリフォルダは、%temp% と入力して下さい。
コードを直接ダウンロードした場合は、右クリックのプロパティより『許可する』にチェックしておきます。
結果の文字列の前後に任意の文字列を追加したい場合 filepath.vbs Wscript.Arguments(0) が目的の文字列なので、この前後に任意の文字列を追加します。
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) & "`" Call WshShell.Run( "cmd.exe /c clip < """ & strPath & """", 0, True )
filelist.vbs aData(Ubound(aData)) が一つのファイル名なので、この前後に任意の文字列を追加します。
Set WshShell = Wscript.CreateObject("WScript.Shell") 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 )
|
【右クリックで「送る」の最新記事】