rclone/cmd/rmdirs/rmdirs.go

39 lines
967 B
Go
Raw Normal View History

2016-11-28 02:36:13 +08:00
package rmdir
import (
"github.com/ncw/rclone/cmd"
"github.com/ncw/rclone/fs"
"github.com/spf13/cobra"
)
var (
leaveRoot = false
)
2016-11-28 02:36:13 +08:00
func init() {
cmd.Root.AddCommand(rmdirsCmd)
rmdirsCmd.Flags().BoolVarP(&leaveRoot, "leave-root", "", leaveRoot, "Do not remove root directory if empty")
2016-11-28 02:36:13 +08:00
}
var rmdirsCmd = &cobra.Command{
Use: "rmdirs remote:path",
Short: `Remove empty directories under the path.`,
2016-11-28 02:36:13 +08:00
Long: `This removes any empty directories (or directories that only contain
empty directories) under the path that it finds, including the path if
it has nothing in.
If you supply the --leave-root flag, it will not remove the root directory.
2016-11-28 02:36:13 +08:00
This is useful for tidying up remotes that rclone has left a lot of
empty directories in.
`,
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args)
fdst := cmd.NewFsDst(args)
cmd.Run(true, false, command, func() error {
return fs.Rmdirs(fdst, "", leaveRoot)
2016-11-28 02:36:13 +08:00
})
},
}