mirror of
https://github.com/rclone/rclone.git
synced 2024-12-27 01:19:12 +01:00
57d5de6fba
git grep -l github.com/ncw/rclone | xargs -d'\n' perl -i~ -lpe 's|github.com/ncw/rclone|github.com/rclone/rclone|g' goimports -w `find . -name \*.go`
41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
package rmdir
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/rclone/rclone/cmd"
|
|
"github.com/rclone/rclone/fs/operations"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
leaveRoot = false
|
|
)
|
|
|
|
func init() {
|
|
cmd.Root.AddCommand(rmdirsCmd)
|
|
rmdirsCmd.Flags().BoolVarP(&leaveRoot, "leave-root", "", leaveRoot, "Do not remove root directory if empty")
|
|
}
|
|
|
|
var rmdirsCmd = &cobra.Command{
|
|
Use: "rmdirs remote:path",
|
|
Short: `Remove empty directories under the path.`,
|
|
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.
|
|
|
|
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.NewFsDir(args)
|
|
cmd.Run(true, false, command, func() error {
|
|
return operations.Rmdirs(context.Background(), fdst, "", leaveRoot)
|
|
})
|
|
},
|
|
}
|