mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: add windows_volume function (#14721)
This commit is contained in:
18
vlib/os/filepath_windows.v
Normal file
18
vlib/os/filepath_windows.v
Normal file
@@ -0,0 +1,18 @@
|
||||
module os
|
||||
|
||||
// windows_volume returns the volume name from the given `path` on a Windows system.
|
||||
// An empty string is returned if no Windows volume is present.
|
||||
// NOTE: An error is returned if the current operating system is not Windows.
|
||||
// Examples (on a Windows system):
|
||||
// ```v
|
||||
// assert os.windows_volume(r'C:\path\to\file.v') == 'C:'
|
||||
// assert os.windows_volume('D:') == 'D:'
|
||||
// assert os.windows_volume(r'\\Host\share\files\file.v') == r'\\Host\share'
|
||||
// ```
|
||||
pub fn windows_volume(path string) string {
|
||||
volume_len := win_volume_len(path)
|
||||
if volume_len == 0 {
|
||||
return empty_str
|
||||
}
|
||||
return path[..volume_len]
|
||||
}
|
||||
Reference in New Issue
Block a user