Page 1 of 1

Using a volume serial number for partitions?

Posted: 20 Apr 2015 13:21
by highend
Don,

can you add the support for targeting partitions via their volume serial number instead of only the drive letter?

Maybe in the form of: {1ECD-8A2C}\

E.g.

Code: Select all

goto "{1ECD-8A2C}\Backup";
It doesn't matter that much for a stationary device because you can use USBDLM to mount a partition to a specific drive letter but on a different PC (and e.g. without admin rights) it would be a great help to be able to get to the correct partition via it's serial and not a drive letter...

Re: Using a volume serial number for partitions?

Posted: 20 Apr 2015 15:02
by yusef88
not sure if they are the same thing
admin wrote:
yusef88 wrote:why xyplorer doesn't handle location like this ?

Code: Select all

\\?\Volume{64CF0AD5-AEE6-11E4-9712-806E6F6E6963}\boot.ini
1. Not supported ATM.

Re: Using a volume serial number for partitions?

Posted: 20 Apr 2015 18:49
by highend
In the meantime:

Code: Select all

$serial = "1ECD-8A2C"; // 2 TB internal drive (normally on T:)
    goto resolveVolumeSerialNumber($serial);

// Resolve the volume serial number of a partition into the corresponding drive letter
function resolveVolumeSerialNumber($volumeSerialNumber) {
    foreach($drive, get("drives")) {
        $drive = trim($drive, "\", "R");
        $serial = regexmatches(runret("cmd /c vol $drive", "%windir%"), "[A-Z0-9]{4}-[A-Z0-9]{4}");
        if ($serial == $volumeSerialNumber) { return $drive; }
    }
    return "<curpath>";
}

Re: Using a volume serial number for partitions?

Posted: 21 Apr 2015 13:11
by eil
highend, that's a very useful script!- even more portability!!. :D
can you please add a script to get this serial easily?

Re: Using a volume serial number for partitions?

Posted: 21 Apr 2015 13:40
by highend
This function returns the serial for one, multiple or all drives depending on what you submit.
Multiple drives must be separated via "|".
It returns "NO SERIAL" if a drive doesn't have one or if the drive is empty. E.g. your DVD-Drive returns
none if no CD / DVD is in it.

You can use:
- The drive letter only
- The drive letter with a trailing ":" or ":\"

Code: Select all

text getVolumeSerialNumber();
    text getVolumeSerialNumber("D");
    text getVolumeSerialNumber("C:|D:")

// Returns the volume serial number for a single / multiple / all drive letter(s)
function getVolumeSerialNumber($driveLetters) {
    $drives = get("drives");
    $output = "";
    if !($driveLetters) { $driveLetters = $drives; }
    foreach($drive, $driveLetters) {
        if (strlen($drive) == 1) { $drive = "$drive:"; }
        $drive = trim($drive, "\", "R");
        $serial = regexmatches(runret("cmd /c vol $drive", "%windir%"), "[A-Z0-9]{4}-[A-Z0-9]{4}");
        if !($serial) { $serial = "NO SERIAL"; }
        $output = $output . "$drive - $serial<crlf>";
    }
    return $output;
}

Re: Using a volume serial number for partitions?

Posted: 21 Apr 2015 14:16
by eil
can't figure out what's wrong, i get this

Code: Select all

Could not find: 
D:\Progs\XYplorer\resolveVolumeSerialNumber(A2F3-1530)
when i try to use 1st script with serial of volume 2st script provided me.

Re: Using a volume serial number for partitions?

Posted: 21 Apr 2015 15:06
by highend
Show your modified 1st script... Maybe you invoked the function with resolveVolumeSerialNumber(A2F3-1530) instead of resolveVolumeSerialNumber("A2F3-1530")?

Which version of XY do you use?

Re: Using a volume serial number for partitions?

Posted: 21 Apr 2015 15:33
by eil

Code: Select all

$serial = "A2F3-1530"; // 2 TB internal drive (normally on T:)
    goto resolveVolumeSerialNumber($serial);

 // Resolve the volume serial number of a partition into the corresponding drive letter
 function resolveVolumeSerialNumber($volumeSerialNumber) {
    foreach($drive, get("drives")) {
        $drive = trim($drive, "\", "R");
        $serial = regexmatches(runret("cmd /c vol $drive", "%windir%"), "[A-Z0-9]{4}-[A-Z0-9]{4}");
        if ($serial == $volumeSerialNumber) { return $drive; }
    }
    return "<curpath>";
 }
15.00.500

Re: Using a volume serial number for partitions?

Posted: 21 Apr 2015 16:01
by highend
15.00.500
This version doesn't even exist :)

Re: Using a volume serial number for partitions?

Posted: 21 Apr 2015 16:10
by bdeshi
it does: www.xyplorer.com/download.php
the beta topic doesn't update when .#00 versions are released.

Re: Using a volume serial number for partitions?

Posted: 21 Apr 2015 16:12
by eil
=)

Re: Using a volume serial number for partitions?

Posted: 21 Apr 2015 16:39
by highend
Oh^^

Code: Select all

function resolveVolumeSerialNumber($volumeSerialNumber) {
   foreach($drive, get("drives")) {
       $drive = trim($drive, "\", "R");
       $serial = regexmatches(runret("cmd /c vol $drive", "%windir%"), "[A-Z0-9]{4}-[A-Z0-9]{4}");
       if ($serial == $volumeSerialNumber) { return $drive; }
   }
   return "<curpath>";
}
You've somehow indented this part of the code, that's the reason why it doesn't work. A line that defines a function can't be indented. So make sure you delete your single spaces before it.

Re: Using a volume serial number for partitions?

Posted: 21 Apr 2015 16:46
by eil
so simple that i feel ashamed. :oops: