Jump to content

CopyPath


Monamo
 Share

Recommended Posts

I know there are other freeware utilities out there to copy file/folder path information to the clipboard, but I wanted to throw something together that was self-contained in an AutoIt package (all of the others I found always had a separate .dll file). So, here ya go:

CopyPath v2.1

Features:

  • Copy the full path of a file or folder to the clipboard
  • Command-line options for installing/uninstalling
  • UNC path support for files and folders on a network share
  • Files/Folders can be dropped onto the executable if you don't want to install the shell context menu.
  • *New* Shortcut file (.LNK, .URL) support added
Usage:

  • Drag and drop a file or folder onto the CopyPath executable to have the full path copied to the clipboard
  • From the command line, use the switch /installhere to create the required registry entries that will reference CopyPath from its current location, creating a shell context menu entry for files and folders
  • From the command line, use the switch /uninstall to remove the CopyPath registry entries (removes context menu item)
CODE

#NoTrayIcon

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****

#AutoIt3Wrapper_icon=.\CopyPath.ico

#AutoIt3Wrapper_outfile=CopyPath.exe

#AutoIt3Wrapper_Compression=4

#AutoIt3Wrapper_Res_Comment=Copies the path of a file or folder to the clipboard.

#AutoIt3Wrapper_Res_Description=CopyPath v2

#AutoIt3Wrapper_Res_Fileversion=2.1.0.0

#AutoIt3Wrapper_Res_Language=1033

#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

Dim $file = ""

Dim $setMsg = ""

If $CmdLine[0] = "0" Then

If Not StringInStr(RegRead("HKEY_CLASSES_ROOT\*\shell\Copy Path to Clipboard\Command", ""), @ScriptFullPath) Then

MsgBox(32, "Not Installed", "CopyPath has not been installed in this location. Use '/installhere' to create the appropriate registry entries.")

Else

MsgBox(32, "Installed", "CopyPath has been installed in this location. Use '/uninstall' to remove registry entries.")

EndIf

_Help()

Exit

Else

Select

Case $CmdLine[1] = "/installhere"

_InstallHere()

Case $CmdLine[1] = "/uninstall"

_Uninstall()

Case $CmdLine[1] = "/help" Or $CmdLine[1] = "-help" Or $CmdLine[1] = "/?" Or $CmdLine[1] = "-?"

_Help()

Case Else

Dim $file = _GetLnkInfo()

If DriveGetType($file) = "NETWORK" Then

If StringInStr($file, ":", 0, 1) = 2 Then

$uncYesNo = MsgBox(36, "Mapped drive path detected", "Would you like the UNC path to be copied to the clipboard?" & @LF & "If so, click 'YES' - Click 'No' to copy the (mapped) drive letter path to the clipboard.")

If $uncYesNo = 6 Then

_GetUNCPath()

Else

EndIf

EndIf

Else

EndIf

EndSelect

EndIf

ClipPut($file)

Func _GetLnkInfo()

Select

Case StringRight($CmdLine[1], 4) = ".lnk"

$getShortcutYesNo = _GetShortcutPrompt()

If $getShortcutYesNo = 6 Then

$shortcutData = FileGetShortcut($CmdLine[1])

$file = $shortcutData[0]

Else

$file = FileGetLongName($CmdLine[1])

EndIf

Case StringRight($CmdLine[1], 4) = ".url"

$getShortcutYesNo = _GetShortcutPrompt()

If $getShortcutYesNo = 6 Then

$file = IniRead($CmdLine[1], "InternetShortcut", "URL", "")

Else

$file = FileGetLongName($CmdLine[1])

EndIf

Case Else

$file = FileGetLongName($CmdLine[1])

EndSelect

Return $file

EndFunc ;==>_GetLnkInfo

Func _GetShortcutPrompt()

$prompt = MsgBox(36, "Shortcut detected", "Would you like the shortcut target path to be copied to the clipboard?" & @LF & "If so, click 'YES' - Click 'No' to copy the path of the " & Chr(34) & "link" & Chr(34) & " file to the clipboard.")

Return $prompt

EndFunc ;==>_GetShortcutPrompt

Func _GetUNCPath()

$mappedDrive = StringTrimRight($file, (StringLen($file) - 2))

$mappedPath = DriveMapGet($mappedDrive)

$uncpath = $mappedPath & StringTrimLeft($file, 2)

$file = $uncpath

EndFunc ;==>_GetUNCPath

Func _InstallHere()

$sScriptPathReg = @ScriptFullPath & " " & Chr(34) & "%1" & Chr(34)

RegWrite("HKEY_CLASSES_ROOT\*\shell\Copy Path to Clipboard\COMMAND", "", "REG_SZ", $sScriptPathReg)

RegWrite("HKEY_CLASSES_ROOT\Folder\shell\Copy Path to Clipboard\command", "", "REG_SZ", $sScriptPathReg)

RegWrite("HKEY_CLASSES_ROOT\lnkfile\shell\Copy Path to Clipboard\command", "", "REG_SZ", $sScriptPathReg)

RegWrite("HKEY_CLASSES_ROOT\InternetShortcut\shell\Copy Path to Clipboard\command", "", "REG_SZ", $sScriptPathReg)

EndFunc ;==>_InstallHere

Func _Uninstall()

RegDelete("HKEY_CLASSES_ROOT\*\shell\Copy Path to Clipboard")

RegDelete("HKEY_CLASSES_ROOT\Folder\shell\Copy Path to Clipboard")

EndFunc ;==>_Uninstall

Func _Help()

MsgBox(64, "CopyPath Help - Version " & FileGetVersion(@ScriptFullPath), "This application is not designed to be run without parameters." & @LF & @LF & "Usage:" & @LF & " - Right-click on a file or folder and select " & Chr(34) & "Copy Path to" & @LF & " Clipboard" & Chr(34) & @LF & @LF & " Or" & @LF & @LF & " - Drag and drop another file or folder directly onto the" & @LF & " CopyPath executable to have the file's full path copied" & @LF & " to the clipboard." & @LF)

EndFunc ;==>_Help

Changelog:

Changes from v2

  • Added shortcut file (*.lnk, *.url) support
Changes from v1

  • Added UNC path support for network source locations

CopyPath.ico

Edited by Monamo

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Link to comment
Share on other sites

Youve added one or two nice touches but other han that you're re-inventing the wheel. There has alread been a couple of these.

#322050

Search the forum for Send To and context menu to find others.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Youve added one or two nice touches but other han that you're re-inventing the wheel. There has alread been a couple of these.

#322050

Search the forum for Send To and context menu to find others.

Ah, never noticed the others - Before I did this, my search params on the forum were "+copy +path +clipboard" with no directly related hits.

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Link to comment
Share on other sites

  • 2 weeks later...

Script updated with extra handling for shortcut files (*.lnk, *.url)

:P

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Link to comment
Share on other sites

  • 9 months later...

Is it possible to make a keyboard shortcut which will invoke the "copy path to clipboard" for a selected file/folder ?

I dont like using the mouse, plus I really dislike going through multiple steps of right-clicking the context menu and then hitting the arrow keys to get to this action.

I saw your registry entry - and if only I could get that %1% information from the selected object (which I selected using the arrow keys on the keyboard). then it should be doable. I dont know autoit very well, hence the question.

So the course of action -

1. I select a file/folder.

2. I use some keyboard shortcut which will copy the path to clipboard.

(thus I do not even need the context menu entry at all)

Thanks,

;)

Edited by aria
Link to comment
Share on other sites

  • 1 year later...

Hi,

I liked that tool very much.

Now I changed from XP (32Bit) to Windows 7 64 Bit and the registration doesn't work anymore.

Does anybody know why? Is it due to the change to 64Bit or is due to the change to Windows 7?

Can anybody help?

Many thanks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...