File tree Expand file tree Collapse file tree 3 files changed +46
-5
lines changed
Expand file tree Collapse file tree 3 files changed +46
-5
lines changed Original file line number Diff line number Diff line change 22
33このディレクトリには以下のサンプルがあります。
44
5- | file | example name | note |
6- | ---------------- | ------------- | --------------------------------------------- |
7- | filepath_walk.go | filepath_walk | filepaths.Walk() のサンプルです. |
8- | filepath_glob.go | filepath_glob | filepath.Glob() の動作についてのサンプルです. |
9-
5+ | file | example name | note |
6+ | ----------------- | ----------------------- | -------- --------------------------------------------- |
7+ | filepath_walk.go | filepath_walk | filepaths.Walk() のサンプルです. |
8+ | filepath_glob.go | filepath_glob | filepath.Glob() の動作についてのサンプルです. |
9+ | exclude_suffix.go | filepath_exclude_suffix | ファイル名から拡張子を除いた値を取得するサンプルです. |
Original file line number Diff line number Diff line change @@ -15,4 +15,5 @@ func NewRegister() mapping.Register {
1515func (r * register ) Regist (m mapping.ExampleMapping ) {
1616 m ["filepath_walk" ] = FilePathWalk
1717 m ["filepath_glob" ] = FilePathGlob
18+ m ["filepath_exclude_suffix" ] = ExcludeSuffix
1819}
Original file line number Diff line number Diff line change 1+ package filepaths
2+
3+ import (
4+ "path/filepath"
5+ "strings"
6+
7+ "github.com/devlights/gomy/output"
8+ )
9+
10+ // ExcludeSuffix は、ファイル名から拡張子を除いた値を取得するサンプルです.
11+ //
12+ // filepath.Ext()とstrings.TrimSuffix()を組み合わせて取得出来ます。
13+ //
14+ // > strings.TrimSuffix(file, filepath.Ext(file))
15+ //
16+ // または、スライスを拡張子分だけカットすることでも取得出来ます。
17+ //
18+ // > file[:len(file)-len(filepath.Ext(file))]
19+ //
20+ // # REFERENCES
21+ // - https://pkg.go.dev/path/filepath@go1.23.4#Ext
22+ // - https://pkg.go.dev/strings@go1.23.4#TrimSuffix
23+ func ExcludeSuffix () error {
24+ var (
25+ fpath = "/path/to/src/something.go"
26+ dir = filepath .Dir (fpath )
27+ fname = filepath .Base (fpath )
28+ ext = filepath .Ext (fname )
29+
30+ base1 = strings .TrimSuffix (fname , ext )
31+ base2 = fname [:len (fname )- len (ext )]
32+ )
33+ output .Stdoutl ("[fpath]" , fpath )
34+ output .Stdoutl ("[dir ]" , dir )
35+ output .Stdoutl ("[ext ]" , ext )
36+ output .Stdoutl ("[base1]" , base1 )
37+ output .Stdoutl ("[base2]" , base2 )
38+
39+ return nil
40+ }
You can’t perform that action at this time.
0 commit comments