Can a dynamic button label show a drive name/label?
I have the following button:
@hideif:=!Exists("K:\")
@icon:"K:\driveicon.ico"
Go K:\
Is there a way with @label
or evaluator code make the button label display the K: drive name or label?
Can a dynamic button label show a drive name/label?
I have the following button:
@hideif:=!Exists("K:\")
@icon:"K:\driveicon.ico"
Go K:\
Is there a way with @label
or evaluator code make the button label display the K: drive name or label?
@label:Root(source)
That would show the current drive letter, not the K drive’s label.
Replace all three lines with something like this:
Go DRIVEBUTTONS=+K,iconlettersoff,lettersbeforelabels
You might want slightly different arguments at the end, depending on how you want the label to look.
What I was hoping to do was make a button that would work as the main button in a button menu. Then the drop-down menu could contain other commands related to the drive. The Go DRIVEBUTTONS
command doesn't work in a button menu (which makes sense because it can show more than one drive).
If I can't get the removable drive's label, I can just use a generic label.
Thanks for the replies.
You can use a script to save the label to a variable and then use the variable in the button.
@hideif:=!Exists("K:\")
@icon:"K:\driveicon.ico"
@label:=$glob:LabelDriveK
Go K:\
function OnInit(initData) {
initData.name = 'GetDriveLabel';
initData.version = '2025-04-14';
initData.url = 'https://resource.dopus.com/t/can-a-dynamic-button-label-show-a-drive-name-label/55393';
initData.desc = 'Get the drive label for a drive letter';
initData.default_enable = true;
initData.min_version = '12.0';
}
var fso = new ActiveXObject('Scripting.FileSystemObject');
var cmd = DOpus.Create().Command();
function OnActivateLister(activateListerData) {
var srcPath = 'K:';
// var srcPath = 'Z:';
var srcLabel = fso.DriveExists(srcPath) ? fso.GetDrive(srcPath).VolumeName : '<none>';
DOpus.vars.Set('LabelDriveK', srcLabel); // reference as $glob:LabelDriveK
cmd.UpdateToggle();
// DOpus.Output('Label Drive ' + srcPath + ' is ' + srcLabel);
}
Save EventGetDriveLabel.js.txt to ↓
%appdata%\GPSoftware\Directory Opus\Script AddIns
Thanks, @lxp, that's great!
Appreciate the help.
The DisplayName evaluator function may do what you want.
Unless I'm doing something wrong, something like @label:=return DisplayName("K:")
or @label:=return DisplayName("K:\")
only gives me "K:\" for a button label and not "SanDisk 4 GB" or whatever.
try
@label: DisplayName(source, "f")
Flag or no flag - DisplayName()
never returns the drive label. Maybe in the future?
Output("nf " + DisplayName("/profile\Folder1\Folder2"));
Output("a: " + DisplayName("/profile\Folder1\Folder2", "a"));
Output("b: " + DisplayName("/profile\Folder1\Folder2", "b"));
Output("c: " + DisplayName("/profile\Folder1\Folder2", "c"));
Output("d: " + DisplayName("/profile\Folder1\Folder2", "d"));
Output("e: " + DisplayName("/profile\Folder1\Folder2", "e"));
Output("f: " + DisplayName("/profile\Folder1\Folder2", "f"));
Output("g: " + DisplayName("/profile\Folder1\Folder2", "g"));
Output("h: " + DisplayName("/profile\Folder1\Folder2", "h"));
Output("i: " + DisplayName("/profile\Folder1\Folder2", "i"));
Output("j: " + DisplayName("/profile\Folder1\Folder2", "j"));
Output("k: " + DisplayName("/profile\Folder1\Folder2", "k"));
Output("l: " + DisplayName("/profile\Folder1\Folder2", "l"));
Output("m: " + DisplayName("/profile\Folder1\Folder2", "m"));
Output("n: " + DisplayName("/profile\Folder1\Folder2", "n"));
Output("o: " + DisplayName("/profile\Folder1\Folder2", "o"));
Output("p: " + DisplayName("/profile\Folder1\Folder2", "p"));
Output("q: " + DisplayName("/profile\Folder1\Folder2", "q"));
Output("r: " + DisplayName("/profile\Folder1\Folder2", "r"));
Output("s: " + DisplayName("/profile\Folder1\Folder2", "s"));
Output("t: " + DisplayName("/profile\Folder1\Folder2", "t"));
Output("u: " + DisplayName("/profile\Folder1\Folder2", "u"));
Output("v: " + DisplayName("/profile\Folder1\Folder2", "v"));
Output("w: " + DisplayName("/profile\Folder1\Folder2", "w"));
Output("x: " + DisplayName("/profile\Folder1\Folder2", "x"));
Output("y: " + DisplayName("/profile\Folder1\Folder2", "y"));
Output("z: " + DisplayName("/profile\Folder1\Folder2", "z"));
Thanks for tut,
last part of path is not drive label
feature request for evaluator drivelabel
please.