|
1 #!perl -w |
|
2 # |
|
3 # Copyright (c) 2010 Symbian Foundation Ltd |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of the License "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Symbian Foundation Ltd - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # Find and output the drive letter mapped to the physical volume with the |
|
16 # largest amount of free space |
|
17 # |
|
18 |
|
19 use strict; |
|
20 |
|
21 # Use Windows command to list physical volumes on the machine |
|
22 # (No substed drives, or mapped network drives) |
|
23 my @drives = map {chomp;$_} `echo list volume | diskpart`; |
|
24 |
|
25 my %drives; |
|
26 for my $driveLine (@drives) |
|
27 { |
|
28 # If this line of output is actually about a healthy HD volume... |
|
29 if ($driveLine =~ m{^\s+Volume \d+\s+([A-Z]).*?(Partition|RAID-5)\s+\d+ [A-Z]+\s+Healthy} ) |
|
30 { |
|
31 my $letter = $1; |
|
32 # Ignore the system drive |
|
33 next if ($driveLine =~ m{System\s*$}); |
|
34 |
|
35 # Use dir to get the freespace (bytes) |
|
36 my @bytesFree = grep { s{^.*?(\d+) bytes free\s*$}{$1} } map {chomp;$_} `cmd /c dir /-C $letter:\\`; |
|
37 # Take the value from the bottom of the report |
|
38 my $bytesFree = $bytesFree[-1]; |
|
39 |
|
40 # Record info for this volume |
|
41 $drives{$letter} = $bytesFree; |
|
42 } |
|
43 } |
|
44 |
|
45 die "Unable to find any suitable drives at all\n" unless %drives; |
|
46 |
|
47 # Switch keys and values |
|
48 %drives = reverse %drives; |
|
49 # Sort by space to find the volume with the largest amount of space and print out the corresponding letter |
|
50 print "$drives{(reverse sort keys %drives)[0]}:\n"; |
|
51 |