Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;original
- ;https://github.com/q2apro/ahk-snippets/blob/master/explorer-navigate-sibling-folder.ahk
- NavigateToSiblingDir(UpDown)
- {
- oShell := ComObjCreate("Shell.Application")
- WinGet, hWnd,, A
- for oWin in oShell.Windows
- {
- if (hWnd = oWin.hwnd)
- {
- oFolder := oWin.Document.Folder
- startDirName := oFolder.Self.Name
- parentDirPath := oFolder.ParentFolder.Self.Path
- break
- }
- }
- ;兄弟フォルダを格納した配列。キーにフォルダ名、値にパス。あとでパスの取得に使う
- siblingFolders := {}
- ;複数のフォルダ名が格納された`nで区切られた文字列。エクスプローラー風のソートに使う
- sortString :=
- for item in oShell.Namespace(parentDirPath).Items
- {
- ;item.IsFolderだとZipファイルもフォルダ扱いになるので変更
- if !InStr(FileExist(item.Path), "D")
- continue
- siblingFolders[item.Name] := item.Path
- sortString .= item.Name "`n"
- }
- sortString := RTrim(sortString, "`n")
- ;StrCmpLogicalWを使ってソート
- Sort, sortString, F SortLikeExplorer
- ;ソート結果に基づいてstartDirName(現在のフォルダ)を基準に直前と直後の兄弟フォルダ名を取得
- Loop, Parse, sortString, `n
- {
- if (found && nextSiblingName := A_LoopField)
- break
- if (A_LoopField = startDirName && found := true)
- prevSiblingName := prev
- prev := A_LoopField
- }
- if (UpDown && prevSiblingName)
- oWin.Navigate(siblingFolders[prevSiblingName])
- if (!UpDown && nextSiblingName)
- oWin.Navigate(siblingFolders[nextSiblingName])
- }
- SortLikeExplorer(lhs, rhs)
- {
- Return DllCall("shlwapi\StrCmpLogicalW", "Str", lhs, "Str", rhs)
- }
Add Comment
Please, Sign In to add comment