github.com/xhghs/rclone@v1.51.1-0.20200430155106-e186a28cced8/cmd/rmdirs/rmdirs.go (about)

     1  package rmdir
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/rclone/rclone/cmd"
     7  	"github.com/rclone/rclone/fs/operations"
     8  	"github.com/spf13/cobra"
     9  )
    10  
    11  var (
    12  	leaveRoot = false
    13  )
    14  
    15  func init() {
    16  	cmd.Root.AddCommand(rmdirsCmd)
    17  	rmdirsCmd.Flags().BoolVarP(&leaveRoot, "leave-root", "", leaveRoot, "Do not remove root directory if empty")
    18  }
    19  
    20  var rmdirsCmd = &cobra.Command{
    21  	Use:   "rmdirs remote:path",
    22  	Short: `Remove empty directories under the path.`,
    23  	Long: `This removes any empty directories (or directories that only contain
    24  empty directories) under the path that it finds, including the path if
    25  it has nothing in.
    26  
    27  If you supply the --leave-root flag, it will not remove the root directory.
    28  
    29  This is useful for tidying up remotes that rclone has left a lot of
    30  empty directories in.
    31  
    32  `,
    33  	Run: func(command *cobra.Command, args []string) {
    34  		cmd.CheckArgs(1, 1, command, args)
    35  		fdst := cmd.NewFsDir(args)
    36  		cmd.Run(true, false, command, func() error {
    37  			return operations.Rmdirs(context.Background(), fdst, "", leaveRoot)
    38  		})
    39  	},
    40  }