Skip to content

Commit a647470

Browse files
committed
adds Temp, TempFile, TempDir funcrtions
1 parent 76f9cbd commit a647470

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

path.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ func ThisDir() Path {
5454
return WD()
5555
}
5656

57+
func Temp(dirs ...string) Path {
58+
f, err := TempFile("", dirs...)
59+
if err != nil {
60+
return New()
61+
}
62+
f.Close()
63+
return New(f.Name())
64+
}
65+
66+
func TempFile(pattern string, dirs ...string) (*os.File, error) {
67+
return os.CreateTemp(filepath.Join(dirs...), pattern)
68+
}
69+
70+
func TempDir(dirs ...string) Path {
71+
return New(append([]string{os.TempDir()}, dirs...)...)
72+
}
73+
5774
func (p Path) String() string {
5875
return string(p)
5976
}

0 commit comments

Comments
 (0)