multiple file rename

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
almatrah
Posts: 2
Joined: 18 Jul 2018, 08:24

multiple file rename

18 Jul 2018, 16:05

Hi Everybody

I found nice script example on the archived forum https://autohotkey.com/board/topic/7671 ... ing-files/.

Code: Select all

debug := true ; change this to false to have it actually rename the files..

#IfWinActive, ahk_class ExploreWClass
#IfWinActive, ahk_class CabinetWClass
f1::  ; remove first 12 chars from beginning of filenames
  SendInput, ^c
  Loop, Parse, clipboard, `n, `r
    Loop, % A_LoopField
      FileMove( A_LoopFileFullPath, SubStr( A_LoopFileName, 12) )
return

f2::  ; add timestamp to beginning of filenames
  FormatTime, dateStamp, YYYYMMDDHH24MISS, yyyy-MM-dd_
  SendInput, ^c
  Loop, Parse, clipboard, `n, `r
    Loop, % A_LoopField
      FileMove( A_LoopFileFullPath, dateStamp A_LoopFileName )
return
#IfWinActive

FileMove(fileFullPath, newFileName){
  global debug
  If debug
    Msgbox, Renaming: `n%fileFullPath%`n`nTo:`n%newFileName%
  Else
    FileMove, %fileFullPath%, %newFileName%
}
The problem is I have to double hit hotkey to run script. Why? What is the reason?
best regards
Paul
[AHK] Version.1.1.28.00 [OS] Win8.1_64
trust_me
Posts: 98
Joined: 29 Jul 2017, 10:46

Re: multiple file rename

20 Jul 2018, 05:56

Not sure but try this:

Code: Select all

debug := true ; change this to false to have it actually rename the files..

#If (WinActive( "ahk_class ExploreWClass") or WinActive( "ahk_class CabinetWClass"))

f1::  ; remove first 12 chars from beginning of filenames
  SendInput, ^c
  Loop, Parse, clipboard, `n, `r
    Loop, % A_LoopField
      FileMove( A_LoopFileFullPath, SubStr( A_LoopFileName, 12) )
return

f2::  ; add timestamp to beginning of filenames
  FormatTime, dateStamp, YYYYMMDDHH24MISS, yyyy-MM-dd_
  SendInput, ^c
  Loop, Parse, clipboard, `n, `r
    Loop, % A_LoopField
      FileMove( A_LoopFileFullPath, dateStamp A_LoopFileName )
return
#If

FileMove(fileFullPath, newFileName){
  global debug
  If debug
    Msgbox, Renaming: `n%fileFullPath%`n`nTo:`n%newFileName%
  Else
    FileMove, %fileFullPath%, %newFileName%
}
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: multiple file rename

20 Jul 2018, 08:10

Because the system need time to complete the copy.

Code: Select all

Clipboard := "" ; Clear the clipboard
SendInput, ^c
ClipWait, 2
I suggest using another approach that does not affect the clipboard.

Code: Select all

debug := true ; change this to false to have it actually rename the files..

#If (WinActive( "ahk_class ExploreWClass") or WinActive( "ahk_class CabinetWClass"))

f1::  ; remove first 12 chars from beginning of filenames
  Loop, Parse, % Explorer_GetSelection(), `n, `r
    Loop, % A_LoopField
      FileMove( A_LoopFileFullPath, SubStr( A_LoopFileName, 12) )
return

f2::  ; add timestamp to beginning of filenames
  FormatTime, dateStamp, YYYYMMDDHH24MISS, yyyy-MM-dd_
  Loop, Parse, % Explorer_GetSelection(), `n, `r
    Loop, % A_LoopField
      FileMove( A_LoopFileFullPath, dateStamp A_LoopFileName )
return
#If

FileMove(fileFullPath, newFileName){
  global debug
  If debug
    Msgbox, Renaming: `n%fileFullPath%`n`nTo:`n%newFileName%
  Else
    FileMove, %fileFullPath%, %newFileName%
}

Explorer_GetSelection()
{
	WinGetClass, class, A
	if (class ~= "Progman|WorkerW")
	{
		ControlGet, files, List, Selected Col1, SysListView321, A
		files := RegExReplace(files, "`am)^", A_Desktop "\")
	}
	else if (class ~= "(Cabinet|Explore)WClass")
	{
		hwnd := WinExist("A")
		for window in ComObjCreate("Shell.Application").Windows
			if (window.hwnd = hwnd)
			{
				for item in window.Document.SelectedItems
					files .= item.path "`n"
				break
			}
	}
	return Trim(files, "`n")
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, Google [Bot], Haris00911, RussF and 307 guests