Page 1 of 1

Script to click and rename a file

Posted: 16 Aug 2022, 04:48
by Martini2000
Hello, there! >OBI WAN KENOBI<

I need to copy paste, a lot of names of videdo files from windows. I have lots of videos and I have to copy their names.
I want to create a script which will MOUSE CLICK + RENAME the file so I can use CTRL+C and copy the name directly, without moving my mouse lots of time.

Do you have any idea, how could I do such a script?

Re: Script to click and rename a file

Posted: 16 Aug 2022, 05:44
by BoBo
Welcome to this Autohotkey forum.

Code: Select all

F12::					;press F12
	path := "C:\myDir\mySubDir\*.mp4"
	Loop, Files,% path
		clipboard .= A_LoopFileName "`n"
	MsgBox % clipboard
return
OTOH, you simply can use Explorers "Copy As Path..."-context menu option :yawn:
https://www.tenforums.com/tutorials/131557-copy-path-file-explorer-windows-10-a.html

Re: Script to click and rename a file

Posted: 16 Aug 2022, 06:00
by zuzu_kuc
You can use Total Commander
just select menu MARK / copy file name OR copy filename with path.

Re: Script to click and rename a file

Posted: 16 Aug 2022, 06:47
by wetware05
I think your requirement is not clear. One by one? The following script copies the name of the file that is under the cursor, to the clipboard, with the typical combination of Crontrol+c.

It makes use of the ACC.ahk library, but the necessary function is built in at the bottom of the script.

Code: Select all

;^F3::
~^C::
TrayTip
FullPath:=Explorer_GetSelection()
;FullPath:=Explorer_GetActiveFolderPath()
MouseGetPos, x1, y1, WinUMID
WinGetClass, WinClass, A
Clipboard:=""

if Not (WinClass = "CabinetWClass" or WinClass = "Progman")
;if Not (WinClass = CabinetWClass or WinClass = Progman)
 {
 Return
 }

oAcc := Acc_ObjectFromPoint(vChildID)
;vChildID := 0 ;for a slightly different result uncomment this line
vText1 := vText2 := ""
try vText1 := oAcc.accName(vChildID) ;get text
try vText2 := oAcc.accValue(vChildID) ;get value
if !(vText1 = "")
	Clipboard .= "`r`n" vText1
/*
if !(vText2 = "") && !(vText = vText2)
	Clipboard .= "`r`n" vText2
*/
oAcc := ""

TrayTip, Filename:, %Clipboard%,, 0x1, 0x10, 0x20
Return

;------------------------------

Explorer_GetSelection() {
   WinGetClass, winClass, % "ahk_id" . hWnd := WinExist("A")
   if !(winClass ~="Progman|WorkerW|(Cabinet|Explore)WClass")
      Return
   
   shellWindows := ComObjCreate("Shell.Application").Windows
   if (winClass ~= "Progman|WorkerW")
      ;shellFolderView := shellWindows.FindWindowSW(0, 0, SWC_DESKTOP := 8, 0, SWFO_NEEDDISPATCH := 1).Document
      shellFolderView := shellWindows.Item( ComObject(VT_UI4 := 0x13, SWC_DESKTOP := 0x8) ).Document
   else {
      for window in shellWindows
         if (hWnd = window.HWND) && (shellFolderView := window.Document)
            break
   }
   for item in shellFolderView.SelectedItems
      result .= (result = "" ? "" : "`n") . item.Path
   if !result
      result := shellFolderView.Folder.Self.Path
   Return result
}

Re: Script to click and rename a file

Posted: 16 Aug 2022, 06:59
by BoBo
Subject line: "Script to click and rename a file" … [to do finally this] … "I have lots of videos and I have to copy their names."
Indeed, a kinda confusing requirement setting. :lolno: