Problema al actualizar a Windows 11

Esta sección es para preguntas sobre programación/scripting usando AutoHotkey.

Moderator: Flipeador

cilniani
Posts: 39
Joined: 30 Oct 2020, 16:15

Problema al actualizar a Windows 11

Post by cilniani » 28 Nov 2022, 14:21

Hola. Tengo un script por el que al pulsar F1 renombro las imágenes que guardo en una carpeta con el nombre de esa carpeta seguida de un número consecutivo. El script funcionaba perfectamente en Windows 10, pero al actualizar a Windows 11 ha dejado de funcionar. Os copio a continuación el script, por si alguien tiene idea de si hay que cambiar algo para que funcione en Windows 11. Saludos y gracias.

Code: Select all

#IfWinActive ahk_exe explorer.exe

SetBatchLines, -1
;-------------------------------hotkeys
F1::
    
;-------------------------------hotkeys

;--------------------------------labels
Renombrar_numerar:
	if WinExist("ahk_class CabinetWClass"){
		ControlGetText currentPath, ToolbarWindow323, ahk_class CabinetWClass
		if (currentPath){
			; pathActiveExplorer := SubStr(currentPath, 10) ;windows en Ingles
			pathActiveExplorer := SubStr(currentPath, 12) 	;windows en español

			FindLast_rename_n(pathActiveExplorer)
		} 
	}
Return

;--------------------------------labels


;--------------------------------Function
FindLast_rename_n(Ruta){
    File := ""
    TimeMod := ""
	
    Loop, Files, %Ruta%\*.*,F
    {
        If (A_LoopFileTimeModified >= TimeMod)
        {
            TimeMod := A_LoopFileTimeModified        ; the time the file was last modified
            File := A_LoopFileFullPath            ; the path and name of the file currently retrieved
        }
        totalFiles := A_Index
    }

    if (File){

        SplitPath, Ruta, NameFolder
        SplitPath, File, , , extFile,

        nameForNewFile := Ruta "\" NameFolder " ("totalFiles ")." extFile

         if (File != nameForNewFile){
            FileMove, %File%, %nameForNewFile% ; Rename a single file.
         } 
    } 
Send, ^!1 
}
;--------------------------------Function

#IfWinActive

gmoises
Posts: 74
Joined: 18 Nov 2017, 16:43

Re: Problema al actualizar a Windows 11

Post by gmoises » 08 Jan 2023, 20:19

Efectivamente, el código funciona en Windows 10, no tengo Windows 11
Te sugiero unas pruebas para que sepas que parte del código no funciona
pongo 2 ejemplos para que sepas si esas dos variables se están asigando bien.

Code: Select all

SetBatchLines, -1
#IfWinActive ahk_exe explorer.exe

;-------------------------------hotkeys
F1::
    
;-------------------------------hotkeys

;--------------------------------labels
Renombrar_numerar:
	if WinExist("ahk_class CabinetWClass"){
		ControlGetText currentPath, ToolbarWindow323, ahk_class CabinetWClass
		if (currentPath){
			; pathActiveExplorer := SubStr(currentPath, 10) ;windows en Ingles
			pathActiveExplorer := SubStr(currentPath, 12) 	;windows en español

; debug -----------------------			
msgbox % pathActiveExplorer
; --------------------------fin

			FindLast_rename_n(pathActiveExplorer)
		} 
	}
Return

;--------------------------------labels


;--------------------------------Function
FindLast_rename_n(Ruta){
    File := ""
    TimeMod := ""
	
    Loop, Files, %Ruta%\*.*,F
    {
        If (A_LoopFileTimeModified >= TimeMod)
        {
            TimeMod := A_LoopFileTimeModified        ; the time the file was last modified
            File := A_LoopFileFullPath            ; the path and name of the file currently retrieved
        }
        totalFiles := A_Index
    }

    if (File){

        SplitPath, Ruta, NameFolder
        SplitPath, File, , , extFile,

        nameForNewFile := Ruta "\" NameFolder " ("totalFiles ")." extFile

         if (File != nameForNewFile){
         
; debug -----------------------			
;            FileMove, %File%, %nameForNewFile% ; Rename a single file.
msgbox % nameForNewFile
; --------------------------fin
         } 
    } 
Send, ^!1 
}
;--------------------------------Function

#IfWinActive
Una función para sacar el Path de una ventana de File Explorer:

Code: Select all

#IfWinActive ahk_class CabinetWClass ahk_exe explorer.exe
	F4::
		MsgBox % GetActiveExplorerPath()
	Return
#If

GetActiveExplorerPath() {			; https://www.autohotkey.com/boards/viewtopic.php?t=69925
	explorerHwnd := WinActive("ahk_class CabinetWClass")
	If (explorerHwnd)
		For window in ComObjCreate("Shell.Application").Windows
			If (window.hwnd = explorerHwnd)
				Return, window.Document.Folder.Self.Path
}

Post Reply

Return to “Pedir Ayuda”