github.com/rclone/rclone@v1.66.1-0.20240517100346-7b89735ae726/cmd/rmdirs/rmdirs.go (about) 1 // Package rmdir provides the rmdir command. 2 package rmdir 3 4 import ( 5 "context" 6 7 "github.com/rclone/rclone/cmd" 8 "github.com/rclone/rclone/fs/operations" 9 "github.com/spf13/cobra" 10 ) 11 12 var ( 13 leaveRoot = false 14 ) 15 16 func init() { 17 cmd.Root.AddCommand(rmdirsCmd) 18 rmdirsCmd.Flags().BoolVarP(&leaveRoot, "leave-root", "", leaveRoot, "Do not remove root directory if empty") 19 } 20 21 var rmdirsCmd = &cobra.Command{ 22 Use: "rmdirs remote:path", 23 Short: `Remove empty directories under the path.`, 24 Long: ` 25 This recursively removes any empty directories (including directories 26 that only contain empty directories), that it finds under the path. 27 The root path itself will also be removed if it is empty, unless 28 you supply the ` + "`--leave-root`" + ` flag. 29 30 Use command [rmdir](/commands/rclone_rmdir/) to delete just the empty 31 directory given by path, not recurse. 32 33 This is useful for tidying up remotes that rclone has left a lot of 34 empty directories in. For example the [delete](/commands/rclone_delete/) 35 command will delete files but leave the directory structure (unless 36 used with option ` + "`--rmdirs`" + `). 37 38 This will delete ` + "`--checkers`" + ` directories concurrently so 39 if you have thousands of empty directories consider increasing this number. 40 41 To delete a path and any objects in it, use the [purge](/commands/rclone_purge/) 42 command. 43 `, 44 Annotations: map[string]string{ 45 "versionIntroduced": "v1.35", 46 "groups": "Important", 47 }, 48 Run: func(command *cobra.Command, args []string) { 49 cmd.CheckArgs(1, 1, command, args) 50 fdst := cmd.NewFsDir(args) 51 cmd.Run(true, false, command, func() error { 52 return operations.Rmdirs(context.Background(), fdst, "", leaveRoot) 53 }) 54 }, 55 }