v / vlib / os
Raw file | 17 loc (16 sloc) | 540 bytes | Latest commit hash 39e54a508
1module os
2
3// windows_volume returns the volume name from the given `path` on a Windows system.
4// An empty string is returned if no Windows volume is present.
5// Examples (on a Windows system):
6// ```v
7// assert os.windows_volume(r'C:\path\to\file.v') == 'C:'
8// assert os.windows_volume('D:') == 'D:'
9// assert os.windows_volume(r'\\Host\share\files\file.v') == r'\\Host\share'
10// ```
11pub fn windows_volume(path string) string {
12 volume_len := win_volume_len(path)
13 if volume_len == 0 {
14 return empty_str
15 }
16 return path[..volume_len]
17}