2016-11-28 02:36:13 +08:00
|
|
|
package rmdir
|
|
|
|
|
|
|
|
import (
|
2019-06-17 16:34:30 +08:00
|
|
|
"context"
|
|
|
|
|
2019-07-29 01:47:38 +08:00
|
|
|
"github.com/rclone/rclone/cmd"
|
|
|
|
"github.com/rclone/rclone/fs/operations"
|
2016-11-28 02:36:13 +08:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2017-12-13 18:23:54 +08:00
|
|
|
var (
|
|
|
|
leaveRoot = false
|
|
|
|
)
|
|
|
|
|
2016-11-28 02:36:13 +08:00
|
|
|
func init() {
|
|
|
|
cmd.Root.AddCommand(rmdirsCmd)
|
2017-12-13 18:23:54 +08:00
|
|
|
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",
|
2017-07-22 01:17:57 +08:00
|
|
|
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.
|
|
|
|
|
2017-12-13 18:23:54 +08:00
|
|
|
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)
|
2018-05-08 00:58:16 +08:00
|
|
|
fdst := cmd.NewFsDir(args)
|
2016-12-05 00:52:24 +08:00
|
|
|
cmd.Run(true, false, command, func() error {
|
2019-06-17 16:34:30 +08:00
|
|
|
return operations.Rmdirs(context.Background(), fdst, "", leaveRoot)
|
2016-11-28 02:36:13 +08:00
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|