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
}
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.
[Codebox=autohotkey file=Untitled.ahk]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
[/Codebox]
Una función para sacar el Path de una ventana de File Explorer:
[Codebox=autohotkey file=Untitled.ahk]#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
}[/Codebox]