Have you ever want a quick way to make a clone of a file in the same folder or copy file names to Microsoft Windows clipboard.
This script creates context-shell menu shortcuts for all files that will provides the folloing functions.
- Create a clone of a file passed as an argument. It appends a prefix to the name of file.
- Copies long file name to clipboard
- Copies long file path to clipboard
Now available as a fast, compiled shell extension. Download FileShellControl (exe file)
Download FileShellControl (vbs file)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- sCloneFilePrefix = "Copy of "
- Set FS = CreateObject ("Scripting.FileSystemObject")
- Set WShell = CreateObject ("WScript.Shell")
- Set args = WScript.Arguments
- sRegPath = "HKCR\*\shell\"
-
- AddReg sRegPath & "Clone\", "Create a C&lone", "a"
- AddReg sRegPath & "CopyFilepath\", "Copy File P&ath", "b"
- AddReg sRegPath & "CopyFilename\", "Copy File Na&me", "c"
-
- If args.Count = 0 Then DisplayHelp ""
- sPath = args(0)
- action = args(1)
- If FS.FileExists(sPath) Then
-
- sLongPath = GetLongFileName(sPath)
-
-
-
- sFileName = FS.GetFileName(sLongPath)
- sNewPath = FS.GetParentFolderName(sLongPath) & "\" & _
- sCloneFilePrefix & sFileName
- Select Case action
- Case "-a"
- FS.CopyFile sLongPath, sNewPath
- Case "-b"
- ClipCopy sLongPath
- Case "-c"
- ClipCopy sFileName
- Case "-d"
- ClipCopy sFileName
- End Select
- Else
- DisplayHelp "Invalid filename."
- End If
-
- Sub AddReg(sRegPath, sName, ArgValue)
- On Error Resume Next
- WShell.RegRead (sRegPath)
- If Err.number <> 0 Then
- WShell.RegWrite sRegPath, sName
- sData = "wscript """ & WScript.ScriptFullName & _
- """ ""%1"" -" & ArgValue
- WShell.RegWrite sRegPath & "command\", sData
- End If
- On Error GoTo 0
- End Sub
-
- Sub ClipCopy(sText)
- On Error Resume Next
- With CreateObject ("InternetExplorer.Application")
- .Navigate "about:blank"
- Do Until .ReadyState = 4
- WScript.Sleep 50
- Loop
- With .document.ParentWindow.ClipboardData
- .SetData "text", sText
- End With
- End With
- End Sub
-
-
- Function GetLongFileName(sPath)
-
- sShortPath = Replace (sPath, "\", "\\")
-
- aPathParts = Split (sShortPath, "\\")
- sLongPath = aPathParts(0)
- For i = 1 To UBound (aPathParts)
- sTmpPath = sLongPath & "\\" & aPathParts(i)
- sQuery = "Select FileName, Extension from Win32_Directory where Name = & _
- sTmpPath & "
- Set FolderSet = GetObject ("winmgmts:").ExecQuery(sQuery)
- For Each oFolder In FolderSet
- sLongPath = sLongPath & "\\" & oFolder.FileName
- If oFolder.Extension <> "" Then
- sLongPath = sLongPath & "." & oFolder.Extension
- End If
- Next
- Next
-
- sQuery = "Select FileName, Extension from CIM_DataFile where Name = & _
- sShortPath & "
- Set FileSet = GetObject ("winmgmts:").ExecQuery(sQuery)
- For Each oFile In FileSet
- sFullFileName = oFile.FileName & "." & oFile.Extension
- Next
- GetLongFileName = Replace (sLongPath & "\" & sFullFileName, "\\", "\")
- End Function
-
- Sub DisplayHelp(msg)
- m_msg = "About this script:" & Chr (13)
- If msg <> "" Then m_msg = m_msg & msg & Chr (13)
- m_msg = m_msg & " [-a | -b | -c] < file >" & Chr (13) & Chr (13)
- m_msg = m_msg & " -a Create a File Clone." & Chr (13)
- m_msg = m_msg & " -b Copy a File Path To Clipboard." & Chr (13)
- m_msg = m_msg & " -c Copy a File Name To Clipboard." & Chr (13)
- MsgBox m_msg
- WScript.Quit - 1
- End Sub
Download FileShellControl (vbs file)