providers/os: Add countFiles function
This commit is contained in:
parent
b974fde7e4
commit
e72523c036
@ -37,6 +37,7 @@ func (this *Provider) FuncMapFor (document *step.Document) template.FuncMap {
|
|||||||
"readDirDate": stat.funcReadDirDate,
|
"readDirDate": stat.funcReadDirDate,
|
||||||
"listFiles": stat.funcListFiles,
|
"listFiles": stat.funcListFiles,
|
||||||
"listFilesDate": stat.funcListFilesDate,
|
"listFilesDate": stat.funcListFilesDate,
|
||||||
|
"countFiles": stat.countFiles,
|
||||||
"writeFile": stat.funcWriteFile,
|
"writeFile": stat.funcWriteFile,
|
||||||
"appendFile": stat.funcAppendFile,
|
"appendFile": stat.funcAppendFile,
|
||||||
"remove": stat.funcRemove,
|
"remove": stat.funcRemove,
|
||||||
@ -145,6 +146,17 @@ func (this *state) funcWriteFile (name, content string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *state) countFiles(name string) (int, error) {
|
||||||
|
name, err := this.document.Rel(name)
|
||||||
|
if err != nil { return err }
|
||||||
|
// genuinely can't believe this is the only way to do it, we have to
|
||||||
|
// read their names and everything, all that work just to know how many
|
||||||
|
// files there are, its slightly upsetting
|
||||||
|
files, err := os.ReadDir(name)
|
||||||
|
if err != nil { return err }
|
||||||
|
return len(files), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (this *state) funcAppendFile (name, content string) error {
|
func (this *state) funcAppendFile (name, content string) error {
|
||||||
name, err := this.document.Rel(name)
|
name, err := this.document.Rel(name)
|
||||||
if err != nil { return err }
|
if err != nil { return err }
|
||||||
|
Loading…
Reference in New Issue
Block a user