From c764388d93af78b34c3374644e36e32eb17a9b02 Mon Sep 17 00:00:00 2001 From: badkaktus Date: Fri, 11 Oct 2019 15:19:29 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=83=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples.txt | 2 +- examples/file-paths/file-paths.go | 46 +++++++++++++++---------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/examples.txt b/examples.txt index e9ae026..51ca2bd 100644 --- a/examples.txt +++ b/examples.txt @@ -58,7 +58,7 @@ Epoch Чтение файлов (Reading Files) Запись файлов (Writing Files) Строковые фильтры (Line Filters) -File Paths +Пути к файлам (File Paths) Directories Temporary Files and Directories Testing diff --git a/examples/file-paths/file-paths.go b/examples/file-paths/file-paths.go index c001dfd..c7fcb6d 100644 --- a/examples/file-paths/file-paths.go +++ b/examples/file-paths/file-paths.go @@ -1,7 +1,7 @@ -// The `filepath` package provides functions to parse -// and construct *file paths* in a way that is portable -// between operating systems; `dir/file` on Linux vs. -// `dir\file` on Windows, for example. +// Пакет `filepath` предоставляет функции для разбора и +// создания *путей к файлам* способом, который переносим +// между операционными системами; например, `dir/file` в +// Linux против `dir\file` в Windows. package main import ( @@ -12,44 +12,44 @@ import ( func main() { - // `Join` should be used to construct paths in a - // portable way. It takes any number of arguments - // and constructs a hierarchical path from them. + // `Join` должен использоваться для создания путей в + // переносимом виде. Он принимает любое количество + // аргументов и строит из них иерархический путь. p := filepath.Join("dir1", "dir2", "filename") fmt.Println("p:", p) - // You should always use `Join` instead of - // concatenating `/`s or `\`s manually. In addition - // to providing portability, `Join` will also - // normalize paths by removing superfluous separators - // and directory changes. + // Вы должны всегда использовать `Join` вместо ручного + // объединения с помощью слешей `/` или `\`. В дополнение + // к обеспечению переносимости, `Join` также нормализует + // пути, удаляя лишние разделители. fmt.Println(filepath.Join("dir1//", "filename")) fmt.Println(filepath.Join("dir1/../dir1", "filename")) - // `Dir` and `Base` can be used to split a path to the - // directory and the file. Alternatively, `Split` will - // return both in the same call. + // `Dir` и `Base` могут использоваться для разделения + // пути к каталогу и файлу. В качестве альтернативы, + // `Split` вернет оба в одном вызове. fmt.Println("Dir(p):", filepath.Dir(p)) fmt.Println("Base(p):", filepath.Base(p)) - // We can check whether a path is absolute. + // Можно проверить является ли путь абсолютным. fmt.Println(filepath.IsAbs("dir/file")) fmt.Println(filepath.IsAbs("/dir/file")) filename := "config.json" - // Some file names have extensions following a dot. We - // can split the extension out of such names with `Ext`. + // Некоторые имена файлов имеют расширения, следующие + // за точкой. Мы можем получить расширение из таких + // имен с помощью `Ext`. ext := filepath.Ext(filename) fmt.Println(ext) - // To find the file's name with the extension removed, - // use `strings.TrimSuffix`. + // Чтобы найти имя файла с удаленным расширением, + // используйте `strings.TrimSuffix`. fmt.Println(strings.TrimSuffix(filename, ext)) - // `Rel` finds a relative path between a *base* and a - // *target*. It returns an error if the target cannot - // be made relative to base. + // `Rel` находит относительный путь между двумя путями + // *base* и *target*. Возвращает ошибку, если *target* + // не может быть получен из *base*. rel, err := filepath.Rel("a/b", "a/b/t/file") if err != nil { panic(err)