# Set working directory when using rclone func

**URL:** <https://forum.rclone.org/t/set-working-directory-when-using-rclone-func/40571>\
**Category:** Dev Discussions\
**Created:** [August 3, 2023, 4:56am UTC](https://forum.rclone.org/t/set-working-directory-when-using-rclone-func/40571 "2023-08-03T04:56:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lechuhuuha](https://forum.rclone.org/user_avatar/forum.rclone.org/lechuhuuha/32/15857_2.png) [@lechuhuuha](https://forum.rclone.org/u/lechuhuuha)\
**Post date:** [August 3, 2023, 4:56am UTC](https://forum.rclone.org/t/set-working-directory-when-using-rclone-func/40571/1 "2023-08-03T04:56:08Z")

</div>

#### What is the problem you are having with rclone?

Currently i create some wrapper around some of rclone func instead of using command line  
But i notice some func should need set current working directory to avoid error  
so how can I set current working directory when using rclone func

#### Which cloud storage system are you using? (eg Google Drive)

None using local

#### Here is the sample wrapper around lsd func of rclone

```go
func Lsd(ctx context.Context, remotePath string, excludeFrom []string) (string, error) {
	var buf bytes.Buffer
	var output string

	newFilterOptions := filter.Opt{
		MinAge: fs.DurationOff,
		MaxAge: fs.DurationOff,
		MinSize: fs.SizeSuffix(-1),
		MaxSize: fs.SizeSuffix(-1),
		RulesOpt: filter.RulesOpt{
			ExcludeFrom: excludeFrom,
		},
	}
	newFilter, err := filter.NewFilter(&newFilterOptions)
	if err != nil {
		return "", fmt.Errorf("error create filter : %w", err)
	}
	ctx = filter.ReplaceConfig(ctx, newFilter)

	fsrc := cmd.NewFsSrc([]string{remotePath})
	err = operations.ListDir(ctx, fsrc, &buf)

	if err != nil {
		return "", err
	}
	// Access the captured output in the buffer
	output = buf.String()
	return output, nil
}

```

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://forum.rclone.org/uploads/default/original/2X/3/39ad3235f6ffec76ccd0c81616bd55697b4c300d.png) [@system](https://forum.rclone.org/u/system)\
**Post date:** [September 2, 2023, 4:57am UTC](https://forum.rclone.org/t/set-working-directory-when-using-rclone-func/40571/2 "2023-09-02T04:57:00Z")

</div>

Closed on September 2, 2023, 4:57am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
