Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@KillyMXI
Last active August 8, 2021 03:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KillyMXI/eceac3cb9115547b62128d14203ee3f0 to your computer and use it in GitHub Desktop.
Save KillyMXI/eceac3cb9115547b62128d14203ee3f0 to your computer and use it in GitHub Desktop.
A pair of buttons for QTTabBar (http://qttabbar.wikidot.com/) to navigate between folders within one common parent folder. More about this: http://mxii.eu.org/2018/12/22/next-folder-previous-folder-navigation-in-explorer-with-qttabbar/
<?xml version="1.0" encoding="utf-8"?>
<CommandButtonInfo>
<MetaData>
<DateCreated>2016-03-24T15:45:16.0981452+03:00</DateCreated>
<Author>MXI</Author>
<Contact>http://mxii.eu.org/</Contact>
<Description>Navigate to the next folder within common parent folder.</Description>
<Version>1.0</Version>
</MetaData>
<CommandButton Type="File" SubType="Normal" PersistentID="20753363">
<FileAction>Default</FileAction>
<DisplayText>Next</DisplayText>
<IconResource>"%SystemRoot%\system32\SHELL32.dll", 247</IconResource>
<IDL>14001F50E04FD020EA3A6910A2D808002B30309D19002F433A5C0000000000000000000000000000000000000056003100000000004D485B7B100057696E646F777300400009000400EFBE1643886C4D485B7B2E000000C5F9030000000200000000000000000000000000000021959900570069006E0064006F0077007300000016005A0031000000000067483A87110053797374656D33320000420009000400EFBE1643896C67483A872E000000DF010400000002000000000000000000000000000000B84C2C00530079007300740065006D00330032000000180062003200006C02005D453C122000637363726970742E65786500480009000400EFBE6246C4A96246C4A92E000000BC4E060000000100000000003D00000000000000000066D8800063007300630072006900700074002E0065007800650000001A000000</IDL>
<Path>%SystemRoot%\System32\cscript.exe</Path>
<Args>
<Item>"C:\THE\PATH\TO\QtTabBar_next_prev_folder.js" next</Item>
</Args>
<ResolutionTimeout>5000</ResolutionTimeout>
<MaxReturnValueWait>0</MaxReturnValueWait>
<Options>0000000000010000000000010300</Options>
</CommandButton>
</CommandButtonInfo>
<?xml version="1.0" encoding="utf-8"?>
<CommandButtonInfo>
<MetaData>
<DateCreated>2016-03-24T15:45:12.1444726+03:00</DateCreated>
<Author>MXI</Author>
<Contact>http://mxii.eu.org/</Contact>
<Description>Navigate to the previous folder within common parent folder.</Description>
<Version>1.0</Version>
</MetaData>
<CommandButton Type="File" SubType="Normal" PersistentID="20807935">
<FileAction>Default</FileAction>
<DisplayText>Prev</DisplayText>
<IconResource>"%SystemRoot%\system32\SHELL32.dll", 246</IconResource>
<IDL>14001F50E04FD020EA3A6910A2D808002B30309D19002F433A5C0000000000000000000000000000000000000056003100000000004D485B7B100057696E646F777300400009000400EFBE1643886C4D485B7B2E000000C5F9030000000200000000000000000000000000000021959900570069006E0064006F0077007300000016005A0031000000000067483A87110053797374656D33320000420009000400EFBE1643896C67483A872E000000DF010400000002000000000000000000000000000000B84C2C00530079007300740065006D00330032000000180062003200006C02005D453C122000637363726970742E65786500480009000400EFBE6246C4A96246C4A92E000000BC4E060000000100000000003D00000000000000000066D8800063007300630072006900700074002E0065007800650000001A000000</IDL>
<Path>%SystemRoot%\System32\cscript.exe</Path>
<Args>
<Item>"C:\THE\PATH\TO\QtTabBar_next_prev_folder.js" prev</Item>
</Args>
<ResolutionTimeout>5000</ResolutionTimeout>
<MaxReturnValueWait>0</MaxReturnValueWait>
<Options>0000000000010000000000010300</Options>
</CommandButton>
</CommandButtonInfo>
var qs = new ActiveXObject( "QTTabBarLib.Scripting" );
var wnd = qs.activewindow;
if ( wnd )
{
// argument value "next" or no arguments - move to next folder
// argument value "prev" or any other - move to previous folder
var lookingForNext = WScript.Arguments.Unnamed.length == 0 || WScript.Arguments.Unnamed(0) == "next";
var activeTab = wnd.ActiveTab;
var currentPath = activeTab.Path;
var fso = new ActiveXObject( "Scripting.FileSystemObject" );
var currentFolderObject = fso.GetFolder(currentPath);
var availablePaths = new Array();
var currentIndex = -1;
var i = -1;
if ( currentFolderObject.IsRootFolder ) // enumerating drives
{
var currentDrive = currentFolderObject.Drive;
var enumerator = new Enumerator(fso.Drives);
for(; !enumerator.atEnd(); enumerator.moveNext())
{
var driveObject = enumerator.item();
i++;
availablePaths[i] = driveObject.Path;
if(driveObject.Path == currentDrive)
{
currentIndex = i;
}
}
}
else // enumerating neighbour folders
{
var enumerator = new Enumerator(currentFolderObject.ParentFolder.SubFolders);
for( ; !enumerator.atEnd(); enumerator.moveNext() )
{
var subFolder = enumerator.item();
if(
!(subFolder.attributes & 4) // ignore system folders
&& !(subFolder.attributes & 1024) // ignore links or shortcuts
//&& !(subFolder.attributes & 2) // ignore hidden folders if needed
)
{
i++;
availablePaths[i] = subFolder.Path;
}
if( subFolder.Path == currentFolderObject.Path )
{
currentIndex = i;
}
}
}
if ( currentIndex >= 0 ) // path found
{
var step = lookingForNext ? 1 : -1;
var newIndex = (availablePaths.length + currentIndex + step) % availablePaths.length;
activeTab.NavigateTo(availablePaths[newIndex]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment