Hi every one,
how to randomly select a fixed number of files in the current directory in windows explorer using a shortcut key
thanks for your time...
how to randomly select a fixed number of files in the current directory in windows explorer using a shortcut key Topic is solved
Re: how to randomly select a fixed number of files in the current directory in windows explorer using a shortcut key
My suggestion is to number the file name, randomly select the number from the numbered array, and then remove the number to get the file name. It is best to make it with a batch script.
Re: how to randomly select a fixed number of files in the current directory in windows explorer using a shortcut key
found this in the forum
can you help?
Code: Select all
SetWorkingDir, ;Folder
total = 0
Loop, *. ;File extension
{
total += 1
}
Random, select, 1, %total%
Loop, *. ;File extension
{
IfEqual, A_Index, %select%, Setenv, file, %A_LoopFileFullPath%
}
MsgBox, %file%
Re: how to randomly select a fixed number of files in the current directory in windows explorer using a shortcut key
and this
but I don't know how to configur theme to my needs
Code: Select all
q:: ;Explorer window/Desktop - focus a random file
;get Explorer object for active window:
if !oWin := JEE_ExpWinGetObj()
return
vCount := oWin.Document.Folder.Items.Count
Random, vNum, 1, % vCount
;SVSI_FOCUSED = 0x10 ;SVSI_ENSUREVISIBLE := 0x8
;SVSI_DESELECTOTHERS := 0x4 ;SVSI_EDIT := 0x3
;SVSI_SELECT := 0x1 ;SVSI_DESELECT := 0x0
oItems := oWin.Document.Folder.Items
if vCount
oWin.Document.SelectItem(oItems.Item(vNum-1), 0x1D)
oWin := oItems := ""
return
;==================================================
JEE_ExpWinGetObj(hWnd:=0)
{
DetectHiddenWindows, On
(!hWnd) && hWnd := WinExist("A")
WinGetClass, vWinClass, % "ahk_id " hWnd
if (vWinClass = "CabinetWClass") || (vWinClass = "ExploreWClass")
{
for oWin2 in ComObjCreate("Shell.Application").Windows
if (oWin2.HWND = hWnd)
{
oWin := oWin2
break
}
}
else if (vWinClass = "Progman") || (vWinClass = "WorkerW")
{
oWindows := ComObjCreate("Shell.Application").Windows
VarSetCapacity(hWnd, 4, 0)
;SWC_DESKTOP := 0x8 ;VT_BYREF := 0x4000 ;VT_I4 := 0x3 ;SWFO_NEEDDISPATCH := 0x1
oWin := oWindows.FindWindowSW(0, "", 8, ComObject(0x4003, &hWnd), 1)
}
return oWin
}
;==================================================
- flyingDman
- Posts: 2837
- Joined: 29 Sep 2013, 19:01
Re: how to randomly select a fixed number of files in the current directory in windows explorer using a shortcut key
This would randomly select 10 files in the current folder in the active Explorer window:
Batch script???
Code: Select all
#\::
list := newlist := ""
if !path := GetActiveExplorerPath()
return
loop, files, % path "\*.*"
list .= (a_index = 1 ? "" : "`n") . A_LoopFileFullPath
sort,list, Random
for x,y in strsplit(list,"`n")
newlist .= a_index = 1 ? y : (x <= 10 ? "`n" y : "") ; 10 <<<<
msgbox % newlist
return
GetActiveExplorerPath(){
if ID := WinActive("ahk_class CabinetWClass")
for window in ComObjCreate("Shell.Application").Windows
if (window.hwnd==ID)
return window.Document.Folder.Self.Path
}
14.3 & 1.3.7
Re: how to randomly select a fixed number of files in the current directory in windows explorer using a shortcut key
I don't know if it is a batch script, I'm a total noob, so, yeah, but I guess it's an AHK script...
or do you mean you can do a batch script for me?
or do you mean you can do a batch script for me?
Re: how to randomly select a fixed number of files in the current directory in windows explorer using a shortcut key Topic is solved
Try this:
Code: Select all
+^1::
+^2::
+^3::
+^4::
+^7::
keys := {1:1,2:25,3:35,4:40,7:70}
choice := keys[SubStr(A_ThisHotkey,3)]
str := sellist := ""
loop, Files, % JEE_ExpWinGetDir() "\*.*", F ; loops in current explorer folder
str .= A_LoopFilename "`n"
sort, str, Random
Loop, Parse, str, `n, `r
{
If (a_index > choice)
break
sellist .= A_LoopField "`n"
}
JEE_ExpWinSetSel(0,sellist) ; select the desired number of files in the current explorer folder
return
JEE_ExpWinGetDir(hWnd:=0)
{
local oWin, oWindows, vDir, vWinClass
DetectHiddenWindows, On
(!hWnd) && hWnd := WinExist("A")
WinGetClass, vWinClass, % "ahk_id " hWnd
if (vWinClass = "CabinetWClass") || (vWinClass = "ExploreWClass")
{
for oWin in ComObjCreate("Shell.Application").Windows
if (oWin.HWND = hWnd)
break
}
else if (vWinClass = "Progman") || (vWinClass = "WorkerW")
{
oWindows := ComObjCreate("Shell.Application").Windows
VarSetCapacity(hWnd, 4, 0)
;SWC_DESKTOP := 0x8 ;VT_BYREF := 0x4000 ;VT_I4 := 0x3 ;SWFO_NEEDDISPATCH := 0x1
oWin := oWindows.FindWindowSW(0, "", 8, ComObject(0x4003, &hWnd), 1)
}
else
return
vDir := oWin.Document.Folder.Self.Path
oWindows := oWin := ""
return vDir
}
JEE_ExpWinSetSel(hWnd, vList, vSep:="`n", vFlagsF:=0x1D, vFlagsS:=0x1)
{
local oItems, oWin, oWindows, vFlags, vName, vWinClass
DetectHiddenWindows, On
(!hWnd) && hWnd := WinExist("A")
WinGetClass, vWinClass, % "ahk_id " hWnd
if (vWinClass = "CabinetWClass") || (vWinClass = "ExploreWClass")
{
for oWin in ComObjCreate("Shell.Application").Windows
if (oWin.HWND = hWnd)
break
}
else if (vWinClass = "Progman") || (vWinClass = "WorkerW")
{
oWindows := ComObjCreate("Shell.Application").Windows
VarSetCapacity(hWnd, 4, 0)
;SWC_DESKTOP := 0x8 ;VT_BYREF := 0x4000 ;VT_I4 := 0x3 ;SWFO_NEEDDISPATCH := 0x1
oWin := oWindows.FindWindowSW(0, "", 8, ComObject(0x4003, &hWnd), 1)
}
else
return
oItems := oWin.Document.Folder.Items
Loop, Parse, vList, % vSep
{
;SVSI_FOCUSED = 0x10 ;SVSI_ENSUREVISIBLE := 0x8
;SVSI_DESELECTOTHERS := 0x4 ;SVSI_EDIT := 0x3
;SVSI_SELECT := 0x1 ;SVSI_DESELECT := 0x0
vFlags := (A_Index = 1) ? vFlagsF : vFlagsS
if !InStr(A_LoopField, "\")
oWin.Document.SelectItem(oItems.Item(A_LoopField), vFlags)
else
{
SplitPath, A_LoopField, vName
oWin.Document.SelectItem(oItems.Item(vName), vFlags)
}
}
oWindows := oWin := oItems := ""
}
Esc::ExitApp
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
Re: how to randomly select a fixed number of files in the current directory in windows explorer using a shortcut key
it gave an error: call to non existent functionflyingDman wrote: ↑17 Jan 2020, 15:22This would randomly select 10 files in the current folder in the active Explorer window:Batch script???Code: Select all
#\:: list := newlist := "" if !path := GetActiveExplorerPath() return loop, files, % path "\*.*" list .= (a_index = 1 ? "" : "`n") . A_LoopFileFullPath sort,list, Random for x,y in strsplit(list,"`n") newlist .= a_index = 1 ? y : (x <= 10 ? "`n" y : "") ; 10 <<<< msgbox % newlist return GetActiveExplorerPath(){ if ID := WinActive("ahk_class CabinetWClass") for window in ComObjCreate("Shell.Application").Windows if (window.hwnd==ID) return window.Document.Folder.Self.Path }
Specifically GetActiveExplorerPath()
Re: how to randomly select a fixed number of files in the current directory in windows explorer using a shortcut key
That function is actually included in the code box. Please copy all the code in the code box, not only the immediately visible part.
Click Expand View to see the whole code (or scroll down in the box), click Select All to select all the code in the code box, ready to be copied.
Change the hotkey (currently #\), if you have other preferences.
Re: how to randomly select a fixed number of files in the current directory in windows explorer using a shortcut key
woooooow man, you nailed it!!!! you did it like a Ninja!Odlanir wrote: ↑18 Jan 2020, 03:35Try this:Code: Select all
+^1:: +^2:: +^3:: +^4:: +^7:: keys := {1:1,2:25,3:35,4:40,7:70} choice := keys[SubStr(A_ThisHotkey,3)] str := sellist := "" loop, Files, % JEE_ExpWinGetDir() "\*.*", F ; loops in current explorer folder str .= A_LoopFilename "`n" sort, str, Random Loop, Parse, str, `n, `r { If (a_index > choice) break sellist .= A_LoopField "`n" } JEE_ExpWinSetSel(0,sellist) ; select the desired number of files in the current explorer folder return JEE_ExpWinGetDir(hWnd:=0) { local oWin, oWindows, vDir, vWinClass DetectHiddenWindows, On (!hWnd) && hWnd := WinExist("A") WinGetClass, vWinClass, % "ahk_id " hWnd if (vWinClass = "CabinetWClass") || (vWinClass = "ExploreWClass") { for oWin in ComObjCreate("Shell.Application").Windows if (oWin.HWND = hWnd) break } else if (vWinClass = "Progman") || (vWinClass = "WorkerW") { oWindows := ComObjCreate("Shell.Application").Windows VarSetCapacity(hWnd, 4, 0) ;SWC_DESKTOP := 0x8 ;VT_BYREF := 0x4000 ;VT_I4 := 0x3 ;SWFO_NEEDDISPATCH := 0x1 oWin := oWindows.FindWindowSW(0, "", 8, ComObject(0x4003, &hWnd), 1) } else return vDir := oWin.Document.Folder.Self.Path oWindows := oWin := "" return vDir } JEE_ExpWinSetSel(hWnd, vList, vSep:="`n", vFlagsF:=0x1D, vFlagsS:=0x1) { local oItems, oWin, oWindows, vFlags, vName, vWinClass DetectHiddenWindows, On (!hWnd) && hWnd := WinExist("A") WinGetClass, vWinClass, % "ahk_id " hWnd if (vWinClass = "CabinetWClass") || (vWinClass = "ExploreWClass") { for oWin in ComObjCreate("Shell.Application").Windows if (oWin.HWND = hWnd) break } else if (vWinClass = "Progman") || (vWinClass = "WorkerW") { oWindows := ComObjCreate("Shell.Application").Windows VarSetCapacity(hWnd, 4, 0) ;SWC_DESKTOP := 0x8 ;VT_BYREF := 0x4000 ;VT_I4 := 0x3 ;SWFO_NEEDDISPATCH := 0x1 oWin := oWindows.FindWindowSW(0, "", 8, ComObject(0x4003, &hWnd), 1) } else return oItems := oWin.Document.Folder.Items Loop, Parse, vList, % vSep { ;SVSI_FOCUSED = 0x10 ;SVSI_ENSUREVISIBLE := 0x8 ;SVSI_DESELECTOTHERS := 0x4 ;SVSI_EDIT := 0x3 ;SVSI_SELECT := 0x1 ;SVSI_DESELECT := 0x0 vFlags := (A_Index = 1) ? vFlagsF : vFlagsS if !InStr(A_LoopField, "\") oWin.Document.SelectItem(oItems.Item(A_LoopField), vFlags) else { SplitPath, A_LoopField, vName oWin.Document.SelectItem(oItems.Item(vName), vFlags) } } oWindows := oWin := oItems := "" } Esc::ExitApp
THaaaaaaaaanks,
just a small question, when I add it to my AHK script file with other scripts, it gives an error (duplicate hotkey) even thought I have no other hotkeys like it in the file, when I run a search, I get only one Instance!
Re: how to randomly select a fixed number of files in the current directory in windows explorer using a shortcut key
Oh, right, I did, but it gives me a list not a selection in the actual explorer windowgregster wrote: ↑18 Jan 2020, 03:42That function is actually included in the code box. Please copy all the code in the code box, not only the immediately visible part.
Click Expand View to see the whole code (or scroll down in the box), click Select All to select all the code in the code box, ready to be copied.
Change the hotkey (currently #\), if you have other preferences.
- flyingDman
- Posts: 2837
- Joined: 29 Sep 2013, 19:01
Re: how to randomly select a fixed number of files in the current directory in windows explorer using a shortcut key
Selected as in highlighted, focused. OK, try this then: (based on the same principle, but a bit more compact)
The question is obviously why do you want to have these files "selected" and don't you want these files in a list or an array eventually...?
Code: Select all
#\::
list := "", WinDoc := GetActiveWinDoc()
if !path := WinDoc.Folder.Self.Path
return
loop, files, % path "\*.*"
list .= (a_index = 1 ? "" : "`n") . A_LoopFileFullPath
sort,list, Random
for x,y in strsplit(list,"`n")
if (x <= 4)
try WinDoc.SelectItem(y, (x = 1 ? 0x1D : 0x1))
return
GetActiveWinDoc(){
if ID := WinActive("ahk_class CabinetWClass")
for window in ComObjCreate("Shell.Application").Windows
if (window.hwnd==ID)
return window.Document
}
14.3 & 1.3.7
Re: how to randomly select a fixed number of files in the current directory in windows explorer using a shortcut key
Oh, the reason is that I'm a teacher at 3 universities, so every one of theme has their own template for paper based multi-choice exam, like 25 questions or 70.... so I have a bank of questions, 345 and growing.... so I need to have a way to randomly select files from the bank folder, because every file is a question.... it's like a lottery of questions if you want to call it like that LOL....flyingDman wrote: ↑18 Jan 2020, 15:31Selected as in highlighted, focused. OK, try this then: (based on the same principle, but a bit more compact)The question is obviously why do you want to have these files "selected" and don't you want these files in a list or an array eventually...?Code: Select all
#\:: list := "", WinDoc := GetActiveWinDoc() if !path := WinDoc.Folder.Self.Path return loop, files, % path "\*.*" list .= (a_index = 1 ? "" : "`n") . A_LoopFileFullPath sort,list, Random for x,y in strsplit(list,"`n") if (x <= 4) try WinDoc.SelectItem(y, (x = 1 ? 0x1D : 0x1)) return GetActiveWinDoc(){ if ID := WinActive("ahk_class CabinetWClass") for window in ComObjCreate("Shell.Application").Windows if (window.hwnd==ID) return window.Document }
Who is online
Users browsing this forum: Bing [Bot], mikeyww and 105 guests