Script Samples
Table of Contents
Save as a js file and execute.
It would be useful if added to AppLauncher or CommandBars.
Open 2 paths in the default view and an extra view
var pathDefault = "C:\\"; var pathExtra = "C:\\Windows"; var extraView = "Left"; // this can be "Bottom" var qs = new ActiveXObject( "QTTabBarLib.Scripting" ); var wnd = qs.activewindow; if( wnd ) { var tab1 = wnd.invokeCommand( "NewTab", pathDefault ); wnd.invokeCommand( "CloseAllButOne", tab1 ); var tab2 = wnd.invokeCommand( "NewTab", pathExtra, null, extraView ); wnd.invokeCommand( "CloseAllButOne", tab2 ); if( wnd.invokecommand( "WindowState" ) != 2 ) wnd.invokecommand( "Restore"); } else { wnd = qs.invokeCommand( "NewWindow", pathDefault ); qs.Sleep( 300 ); var tab = wnd.invokeCommand( "NewTab", pathExtra, null, extraView ); wnd.invokeCommand( "CloseAllButOne", tab ); }
Copy file sizes of selected items to ClipBoard
var qs = new ActiveXObject( "QTTabBarLib.Scripting" ); var wnd = qs.ActiveWindow; var tab = wnd.ActiveTab; var sel = tab.selectedItems; if( sel.Count ) { var single = sel.Count == 1; var str = ""; var fso = new ActiveXObject( "Scripting.FileSystemObject" ); for( var i = 0; i < sel.Count; i++ ) { var path = sel.Item( i ); if( fso.FileExists( path ) ) { if( single ) { str += fso.GetFile( path ).Size; } else { str += path + ", "+ fso.GetFile( path ).Size + "\r\n"; } } else if( fso.FolderExists( path ) ) { if( single ) { str += fso.GetFolder( path ).Size; } else { str += path + ", "+ fso.GetFolder( path ).Size + "\r\n"; } } } wnd.InvokeCommand( "SetClipboard", str ); }
Search duplicated files in the current folder / selected files
var qs = new ActiveXObject( "QTTabBarLib.Scripting" ); var wnd = qs.FocusedWindow; if( wnd ) { var fso = new ActiveXObject( "Scripting.FileSystemObject" ); var sel = wnd.selectedItems; var targets = qs.NewCollection(); if( sel && sel.Count > 0 ) { for( var i = 0; i < sel.Count; i++ ) { var path = sel.Item( i ); if( fso.FileExists( path ) ) { targets.Add( path ); } } } else { var current = wnd.ActiveTab.Path; if( fso.FolderExists( current ) ) { var files = fso.GetFolder( current ).Files; var fc = new Enumerator( files ); for(; !fc.atEnd(); fc.moveNext() ) { targets.Add( fc.item().Path ); } } } if( targets && targets.Count > 0 ) { var dic = new Object(); for( var i = 0; i < targets.Count; i++ ) { var path = targets.Item( i ); var hash = wnd.InvokeCommand( "ComputeFileHash", path ); if( hash ) { if( !dic[hash] ) { dic[hash] = qs.NewCollection(); } dic[hash].Add( path ); } } var str = ""; for( var s in dic ) { var col = dic[s]; if( col.Count > 1 ) { str += "These are identical:\n"; for( var i = 0; i < col.Count; i++ ) { str += col.Item( i ) + "\n"; } str += "\n"; } } if( str ) { if( 6 == qs.Messagebox( str + "\nDo you want to send to Clipboard?", "YesNo" ) ) { qs.InvokeCommand( "SetClipboard", str ); } } else { qs.alert( "No duplication." ); } } else { qs.alert( "No file exists." ); } }
Convert selected file names to uppercase / lowercase
e.g. Abc Def -> ABC DEF -> abc def -> Abc Def
var qs = new ActiveXObject( "QTTabBarLib.Scripting" ); var wnd = qs.FocusedWindow; if( wnd ) { var sel = wnd.selectedItems; if( sel.Count ) { var fso = new ActiveXObject( "Scripting.FileSystemObject" ); for( var i = 0; i < sel.Count; i++ ) { var path = sel.Item( i ); var name = fso.GetFileName( path ); if( UpperAtFirstChar( name ) != name ) { qs.InvokeCommand( "Rename", path, UpperAtFirstChar( name ) ); } else if( UpperCased( name ) ) { qs.InvokeCommand( "Rename", path, name.toLowerCase() ); } else { qs.InvokeCommand( "Rename", path, name.toUpperCase() ); } } } } function UpperCased( str ) { for( var i = 0; i < str.length; i++ ) { var ch = str.charAt( i ); if( ( "a" <= ch && ch <= "z" ) || ( "A" <= ch && ch <= "Z" ) ) { if( ch.toUpperCase() != ch ) { return false; } } } return true; } function LowerCased( str ) { for( var i = 0; i < str.length; i++ ) { var ch = str.charAt( i ); if( ( "a" <= ch && ch <= "z" ) || ( "A" <= ch && ch <= "Z" ) ) { if( ch.toLowerCase() != ch ) { return false; } } } return true; } function UpperAtFirstChar( str ) { var arr = str.split( " " ); for( var i = 0; i < arr.length; i++ ) { if( arr[i] ) { if( arr[i].length > 1 ) { arr[i] = arr[i].charAt( 0 ).toUpperCase() + arr[i].substring( 1 ); } else { arr[i] = arr[i].charAt( 0 ).toUpperCase(); } } } return arr.join( " " ); }