2011-06-16 82 views
0

我試圖找到一個腳本,將讓我在XP上右鍵單擊文件(或7),然後選擇和選項(如「複製到MyServer的「)。VBS腳本複製文件,然後複製路徑和文件名到剪貼板

這將會把文件拷貝到設定的位置,然後它會那麼該文件的文件路徑和名稱複製到剪貼板,這樣我可以該位置粘貼到別的東西。 (我想將它粘貼到我的幫助臺,只接受圖片的URL)

所以基本上這會讓我複製我的計算機上的圖片到特定的服務器,然後將位置粘貼到我的表單中。合理?

我發現了一些VBS代碼,將複製一個文件,以及一些VBS代碼,可以讓我用鼠標右鍵單擊文件,以獲得顯示的位置。但我不知道如何合併它們。任何想法如何做到這一點?

複製代碼:

Dim FSO 
Set FSO = CreateObject("Scripting.FileSystemObject") 
FSO.CopyFile "\\file to be copied path", "\\destination directory" 

獲取路徑代碼(需要一個註冊表編輯在上下文菜單中會顯示):

set oFso = createObject("scripting.filesystemobject") 

if wscript.arguments.count >= 1 then 

    strPath = wscript.arguments(0) 


    strDriveName = ofso.GetDriveName(strPath) 

    set oDrive = ofso.GetDrive(strDriveName) 



    Select Case oDrive.DriveType 
      Case 0: t = "Unknown" 
     Case 1: t = "Removable" 
     Case 2: t = "Fixed" 
     Case 3: t = "Network" 
     Case 4: t = "CD-ROM" 
     Case 5: t = "RAM Disk" 
    End Select 

    strFileName = ofso.GetFileName(strPath) 

    test = inputbox("The path is...","Path", strPath) 

else 

    msgbox "no args" 

end if 

回答

2

此代碼將一個參數(文件名)並將其移動到代碼頂部的sLocation中定義的位置。完成後,它將顯示確認信息並將剪貼板中的文件路徑(位於新位置)粘貼。

據我所知,VBScript沒有能力直接操作剪貼板,所以我們把它交給MSDOS clip命令來做到這一點。

Option Explicit 
' Change sLocation in the line below to the folder you want to move files to. 
Dim sLocation : sLocation = "C:\Temp" 
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject") 
Dim wsh : Set wsh = WScript.CreateObject("WScript.Shell") 
If WScript.Arguments.Count = 0 Then 
    MsgBox "Missing a filename!" 
    WScript.Quit 
End If 
If fso.FileExists(WScript.Arguments(0)) = False Then 
    MsgBox "File '" & WScript.Arguments(0) & "' doesn't exist!" 
    WScript.Quit 
End If 
Dim oFile : Set oFile = fso.GetFile(WScript.Arguments(0)) 
fso.CopyFile oFile.Path, sLocation 
Dim sNewLocation : sNewLocation = sLocation & "\" & oFile.Name 
wsh.Run "cmd.exe /c echo " & sNewLocation & "| clip", 0, True 
Msgbox "File moved to " & sNewLocation & VbCrLf & "and new path copied to clipboard." 
Set fso = Nothing 
Set wsh = Nothing 
Set oFile = Nothing 

要安裝,你需要或者添加註冊表項,以便該腳本稱爲一個項目時,右鍵單擊或你爲了打通「發送到」文件夾,並把運行以下命令shell:sendto這是劇本的捷徑。如果你使用後者,那麼你應該能夠右鍵點擊一個文件並從「發送到」菜單中選擇腳本。

+0

喜歡這個短片解決方案! 大多數其他解決方案依賴於IE瀏覽器,現在提示用戶訪問到剪貼板。如果您沒有顯示IE,那麼腳本會自動失敗。 這個剪輯解決方案效果很好。 :-) – 2017-05-11 01:22:24