Documentation ¶
Overview ¶
Package windows implements a number of Windows specific features; such as to-and-from system encoding and UTF-8, along with functional APIs for programmatically interacting with paths and files.
Index ¶
- Constants
- Variables
- func ComputerName() (name string, e error)
- func ConfigDirectory() (dir string, e error)
- func ConfigHomeDirectory() (dir string, e error)
- func DataHomeDirectory() (dir string, e error)
- func GetSystemCodePage() (cp int)
- func HomeDirectory() (dir string, e error)
- func SystemCodePageToUtf8(text string) (s string, e error)
- func SystemDirectory() (dir string, e error)
- func Utf8ToSystemCodePage(text string) (s string, e error)
- type PathImpl
- func (p *PathImpl) Device() string
- func (p *PathImpl) Dirs() []string
- func (p *PathImpl) Errors() []error
- func (p *PathImpl) IsAbsolute() bool
- func (p *PathImpl) IsDirectoryExists() bool
- func (p *PathImpl) IsLocal() bool
- func (p *PathImpl) IsRelative() bool
- func (p *PathImpl) IsRemote() bool
- func (p *PathImpl) MakeAbsolute() *PathImpl
- func (p *PathImpl) MakeDirectory() *PathImpl
- func (p *PathImpl) Name() string
- func (p *PathImpl) Node() string
- func (p *PathImpl) ToString() string
- func (p *PathImpl) ToUnicodeUNC() string
Constants ¶
const ( CP1252 int = 1252 UnicodeFFFE = 1201 Macintosh = 10000 UTF32 = 12000 UTF32BE = 12001 UsASCII = 20127 ISO88591 = 28591 ISO88592 = 28592 UTF7 = 65000 UTF8 = 65001 )
Possible Windows Code Pages
Variables ¶
var ErrInvalidDrive = errors.New("path: invalid drive specified")
ErrInvalidDrive indicates an invalid character was used as a drive letter.
var ErrInvalidEncoding = errors.New("windows: invalid string encoding")
ErrInvalidEncoding is returned as a result of an invalid conversion.
var ErrInvalidNarrow = errors.New("windows: invalid narrow encoded string")
ErrInvalidNarrow is returned as a result of an invalid conversion to a narrow byte sequence.
var ErrInvalidWide = errors.New("windows: invalid wide-character encoded string")
ErrInvalidWide is returned as a result of an invalid conversion to a wide-character sequence.
Functions ¶
func ComputerName ¶
ComputerName returns the NetBIOS machine name. There are edge-cases for a seemingly wrong machine name to be returned. See the reference below for information on when this occurs.
See also MSDN, “GetComputerName function,” https://msdn.microsoft.com/en-us/library/windows/desktop/ms724295(v=vs.85).aspx
func ConfigDirectory ¶
ConfigDirectory returns the running machine's application configuration and/or local data directory. Write access may require Administrator privileges.
func ConfigHomeDirectory ¶
ConfigHomeDirectory returns the current user's application configuration directory on the user's roaming profile. All configuration file written are possibly synchronized between multiple machines the user may have access to.
func DataHomeDirectory ¶
DataHomeDirectory returns the current user's application data configuration directory on the user's local, specific to the current machine, profile. All configuration data written are only stored on the current machine. For possibly synchronized configuration data, see ConfigHomeDirectory().
func GetSystemCodePage ¶
func GetSystemCodePage() (cp int)
GetSystemCodePage returns Window's default system code page.
func HomeDirectory ¶
HomeDirectory returns the current user's directory on the machine; typically a folder inside the “C:\Users” directory.
func SystemCodePageToUtf8 ¶
SystemCodePageToUtf8 converts the given string from Window's system code page to an UTF-8 string.
func SystemDirectory ¶
SystemDirectory returns the machine's system path location; typically “C:\WINDOWS\system32”.
func Utf8ToSystemCodePage ¶
Utf8ToSystemCodePage converts the given UTF-8 string to Window's system code page.
Types ¶
type PathImpl ¶
type PathImpl struct {
// contains filtered or unexported fields
}
PathImpl holds state between each of the functional calls returned by Path().
func Path ¶
Path parses a local or remote file or directory by purely lexical processing, and returns an object for use through functional semantics.
It is able to parse the following types of input:
- Relative file or directory
- Absolute file or directory
- UNC file or directory
- UNICODE absolute file or directory
- UNICODE UNC file or directory
Errors are collected during the parsing, for all possible validation errors describe by the referenced MSDN article later described.
See also MSDN, “Naming Files, Paths, and Namespaces,” https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
func (*PathImpl) Errors ¶
Errors returns an array of all parse and validation errors encountered when parsing.
func (*PathImpl) IsAbsolute ¶
IsAbsolute checks whether the Path refers to a non-relative location.
func (*PathImpl) IsDirectoryExists ¶
IsDirectoryExists checks whether the Path refers to an existing directory.
func (*PathImpl) IsLocal ¶
IsLocal checks whether the Path refers to a location on the current machine.
func (*PathImpl) IsRelative ¶
IsRelative checks whether the Path refers to a non-absolute location.
func (*PathImpl) IsRemote ¶
IsRemote checks whether the Path refers to a location that is not on the current machine.
func (*PathImpl) MakeAbsolute ¶
MakeAbsolute checks whether the Path refers to a relative location on the current machine. If so, it non-destructively converts the relative location to an absolute one by querying the path through the operating system.
Because MakeAbsolute is non-destructive, the returned pointer to PathImpl may NOT be the same as called with!
func (*PathImpl) MakeDirectory ¶
MakeDirectory checks whether the Path has a Name(). If so, the Name() is added to the set of Dirs() and is cleared.
func (*PathImpl) ToUnicodeUNC ¶
ToUnicodeUNC returns a fully-qualified UNICODE UNC representation of the parsed Path.