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.

Now available as a fast, compiled shell extension. Download FileShellControl (exe file)

Download FileShellControl (vbs file)

  1. ' *********************************************************
  2. ' FILE: FileShellControl.vbs
  3. ' VERSION: 1.2.1
  4. ' CREATED: 5/25/2004
  5. ' UPDATED: 6/11/2004
  6. ' AUTHOR: Scott Greenberg
  7. ' Company: SG Technology
  8. ' Website: http://gogogadgetscott.info
  9. ' DECRIPTION: Perform serval file operations including,
  10. ' creating a clone of file With a New filename prefix (Copy of * _),
  11. ' copy file name To clipboard, copy file path To clipboard.
  12. ' Add sortcuts To context shell menu.
  13. ' File name passed As an argument.
  14. ' COMMENT: Requires Microsoft internet Explorer 5+
  15. ' CHANGE Log :
  16. ' 1.2.1: 06/11/2004 - Fixed duplicate file extensions
  17. '   1.2: 06/11/2004 - Fixed GetLongFileName To allow periods, (.) In folder name
  18. '   1.1: 06/01/2004 - Update GetLongFileName To Return full path In Long format
  19. ' To Do :
  20. '    N/A
  21. ' Copyright© 2004. SG Technology. All rights reserved.
  22. ' *********************************************************
  23. sCloneFilePrefix = "Copy of "
  24. Set FS = CreateObject ("Scripting.FileSystemObject")
  25. Set WShell = CreateObject ("WScript.Shell")
  26. Set args = WScript.Arguments
  27. sRegPath = "HKCR\*\shell\"
  28. ' Comment out any undesired Option here
  29. AddReg sRegPath & "Clone\", "Create a C&lone", "a"
  30. AddReg sRegPath & "CopyFilepath\", "Copy File P&ath", "b"
  31. AddReg sRegPath & "CopyFilename\", "Copy File Na&me", "c"
  32. ' Get command line aguments
  33. If args.Count = 0 Then DisplayHelp ""
  34. sPath = args(0)
  35. action = args(1)
  36. If FS.FileExists(sPath) Then
  37.   ' Convert short To Long path
  38.   sLongPath = GetLongFileName(sPath)
  39.   'MsgBox sLongPath
  40.   'WScript.Quit
  41.   ' Create New clone path
  42.   sFileName = FS.GetFileName(sLongPath)
  43.   sNewPath = FS.GetParentFolderName(sLongPath) & "\" & _
  44.   sCloneFilePrefix & sFileName
  45.   Select Case action
  46.   Case "-a"
  47.     FS.CopyFile sLongPath, sNewPath
  48.   Case "-b"
  49.     ClipCopy sLongPath
  50.   Case "-c"
  51.     ClipCopy sFileName
  52.   Case "-d"
  53.     ClipCopy sFileName
  54.   End Select
  55. Else
  56.   DisplayHelp "Invalid filename."
  57. End If
  58. ' Add registy entry To create file context shell item
  59. Sub AddReg(sRegPath, sName, ArgValue)
  60.   On Error Resume Next
  61.   WShell.RegRead (sRegPath)
  62.   If Err.number <> 0 Then
  63.     WShell.RegWrite sRegPath, sName
  64.     sData = "wscript """ & WScript.ScriptFullName & _
  65.     """ ""%1"" -" & ArgValue
  66.     WShell.RegWrite sRegPath & "command\", sData
  67.   End If
  68.   On Error GoTo 0
  69. End Sub
  70. ' Copy String To clipboard
  71. Sub ClipCopy(sText)
  72.   On Error Resume Next
  73.   With CreateObject ("InternetExplorer.Application")
  74.     .Navigate "about:blank"
  75.     Do Until .ReadyState = 4
  76.       WScript.Sleep 50
  77.     Loop
  78.     With .document.ParentWindow.ClipboardData
  79.       .SetData "text", sText
  80.     End With ' ClipboardData
  81.   End With ' IE
  82. End Sub
  83. ' Get Long File/Path Name, using winmgmts
  84. ' requred becouse argument passed Is In short 8.3 format
  85. Function GetLongFileName(sPath)
  86.   ' Query requires path format w/ "\\" i.e. C:\\windows\\win.ini
  87.   sShortPath = Replace (sPath, "\", "\\")
  88.   ' Get Long folder name, one at a time
  89.   aPathParts = Split (sShortPath, "\\")
  90.   sLongPath = aPathParts(0)
  91.   For i = 1 To UBound (aPathParts)
  92.     sTmpPath = sLongPath & "\\" & aPathParts(i)
  93.     sQuery = "Select FileName, Extension from Win32_Directory where Name = '" & _
  94.     sTmpPath & "'"
  95.     Set FolderSet = GetObject ("winmgmts:").ExecQuery(sQuery)
  96.     For Each oFolder In FolderSet
  97.       sLongPath = sLongPath & "\\" & oFolder.FileName
  98.       If oFolder.Extension <> "" Then
  99.         sLongPath = sLongPath & "." & oFolder.Extension
  100.       End If
  101.     Next
  102.   Next
  103.   ' Get Long file name
  104.   sQuery = "Select FileName, Extension from CIM_DataFile where Name = '" & _
  105.   sShortPath & "'"
  106.   Set FileSet = GetObject ("winmgmts:").ExecQuery(sQuery)
  107.   For Each oFile In FileSet
  108.     sFullFileName = oFile.FileName & "." & oFile.Extension
  109.   Next
  110.   GetLongFileName = Replace (sLongPath & "\" & sFullFileName, "\\", "\")
  111. End Function
  112. ' Display help infomation
  113. Sub DisplayHelp(msg)
  114.   m_msg = "About this script:" & Chr (13)
  115.   If msg <> "" Then m_msg = m_msg & msg & Chr (13)
  116.   m_msg = m_msg & " [-a | -b | -c] < file >" & Chr (13) & Chr (13)
  117.   m_msg = m_msg & " -a Create a File Clone." & Chr (13)
  118.   m_msg = m_msg & " -b Copy a File Path To Clipboard." & Chr (13)
  119.   m_msg = m_msg & " -c Copy a File Name To Clipboard." & Chr (13)
  120.   MsgBox m_msg
  121.   WScript.Quit - 1
  122. End Sub

Download FileShellControl (vbs file)