use Win32;
my $next_drive = Win32::GetNextAvailDrive();
If you have drives "A:" through "D:", this returns "E:".
_____________________________________________________
Jeff japhy Pinyan,
P.L., P.M., P.O.D, X.S.:
Perl,
regex,
and perl
hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
| [reply] [d/l] |
Hello,
If I would like to choose 4 free drives, and I run the Win32::GetNextAvailDrive() 4 times, it gives me the same drive everytime, not different ones.
Is there a way I can find out more than one available drive?
Thanks
| [reply] |
What you would want to do, then, is use each one in a loop, rather than getting them ahead of time. That is, rather than:
my @drives = (
Win32::GetNextAvailDrive(),
Win32::GetNextAvailDrive(),
Win32::GetNextAvailDrive(),
Win32::GetNextAvailDrive(),
);
do_stuff_with(@drives);
do this:
for (1..4)
{
my $drive = Win32::GetNextAvailDrive();
do_stuff_with($drive);
}
Hopefully, do_stuff_with() will net use or something so that the drive becomes unavailable (in use) so the next time through, Win32::GetNextAvailDrive will get a new drive. | [reply] [d/l] [select] |
Thank you all for your replies
| [reply] |
my @letters = 'E' .. 'Z';
my $drive = $letters[rand scalar @letters];
As you remove letters (say, using splice from @letters), this would continue to work.
Update: Yes, as Limbic~Region points out, the scalar is probably superfluous. I just like being explicit - especially when I'm not looking at the docs to see what the parameters really are. ;-)
Update2: Typo - had slice rather than splice. Thanks to Limbic~Region for pointing it out. | [reply] [d/l] |
Tanktalus,
The scalar is superfluous. I would probably use a closure that knows to refill @letters once it is empty if I was going the splice route. OTOH, if I didn't need to remove elements I probably wouldn't use the array at all:
my $drive = chr( int(rand 26) + 65 );
| [reply] [d/l] |
my $random_upper_case_letter = chr(int(rand(26)+1)+65);
| [reply] |
From a batch file or command line, you can say
net use * \\server\resource
for windoze itself to assign to the next available drive letter...
-Scott | [reply] [d/l] |