Hellbent wrote: ↑01 Nov 2023, 15:33
Give this a try.
Code: Select all
#SingleInstance Force
Gui1 := {} ;create a structure to hold the variables associated with the window. (henceforth: "Object")
Gui, New, +AlwaysOnTop +hwndhwnd ;create your new window
Gui1.Hwnd := hwnd ;add the handle of the window to the window object.
;add other controls
;blah blah
;blah
Gui, Show, w300 h300 ,DropFiles Demo ;Show the window
Return ;End of Auto-Execute Section
GuiClose: ;exit routine
GuiContextMenu:
*Esc::ExitApp
GuiDropFiles: ;{
if( A_Gui != Gui1.Hwnd ) ;Do nothing if it's the wrong window
return
arr := StrSplit( A_GuiEvent , "`n" ) ;split the paths
dateTimePrefixPattern := "^\d{2}-\d{2}-\d{4} {\d{2}\.\d{2}\.\d{2}\.\w{2}}_"
for k , v in arr { ;loop through the paths
FileGetAttrib, Attributes, % arr[ k ] ;get the Attributes
if( instr( Attributes , "D" ) ){ ;test if the path is a directory
msgbox, % "This is a folder`n" arr[ k ] ;the path is a directory, have at it.
}else{
msgbox, % "NOT a folder`n" arr[ k ] ;the path isn't a directory.
}
}
;your old code.
/*
; Loop through all files and subfolders in the selected folder
Loop, Files, %sourceFolder%\*, R
{
if (RegExMatch(A_LoopFileName, dateTimePrefixPattern))
continue
FileGetTime, modifiedTime, %A_LoopFileLongPath%, M
FormatTime, modifiedTime, %modifiedTime%, yyyy-MM-dd {hh.mm.ss.tt}_
newFilename := A_LoopFileDir . "\" . modifiedTime . "_" . A_LoopFileName
FileMove, %A_LoopFileLongPath%, %newFilename%
}
*/
voice := ComObjCreate("SAPI.SpVoice")
voice.volume := 100
voice.Speak("Files Renamed")
return
;}
I can't thank you enough for getting me started, thank you SO much! I made some final touches to make it look nicer and display the path in the GUI. Just gonna share the completed script in case someone also needs a script that rename all files inside a folders as modified date in year-month-day {12 hours time} format. Have a great day!
Code: Select all
Gui1 := {}
Gui, New, +AlwaysOnTop +hwndhwnd
Gui1.Hwnd := hwnd
Gui, Add, ListView, w500 h400 vMyListView, Name
Gui, Add, Button, gStartRenaming x250 y420, Rename
Gui, Show, w550 h450 ,DropFiles to Rename with modified date in [yyyy-MM-dd + time]
Return
GuiClose:
GuiContextMenu:
*Esc::ExitApp
GuiDropFiles:
if( A_Gui != Gui1.Hwnd )
return
arr := StrSplit( A_GuiEvent , "`n" )
dateTimePrefixPattern := "^\d{4}-\d{2}-\d{2} {\d{2}\.\d{2}\.\d{2}\.\w{2}}_"
for k , v in arr {
FileGetAttrib, Attributes, % arr[ k ]
if( instr( Attributes , "D" ) ){
LV_Add("", arr[k])
}
}
return
StartRenaming:
Loop, % LV_GetCount()
{
LV_GetText(sourceFolder, A_Index)
Loop, Files, %sourceFolder%\*, R
{
if (RegExMatch(A_LoopFileName, dateTimePrefixPattern))
continue
FileGetTime, modifiedTime, %A_LoopFileLongPath%, M
FormatTime, modifiedTime, %modifiedTime%, yyyy-MM-dd {hh.mm.ss.tt}_
newFilename := A_LoopFileDir . "\" . modifiedTime . "_" . A_LoopFileName
FileMove, %A_LoopFileLongPath%, %newFilename%
}
}
voice := ComObjCreate("SAPI.SpVoice")
voice.volume := 100
voice.Speak("Files Renamed")
ExitApp
return