2016-08-05 18:12:27 +02:00
|
|
|
package move
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ncw/rclone/cmd"
|
2018-05-07 19:13:17 +02:00
|
|
|
"github.com/ncw/rclone/fs/operations"
|
2018-01-12 17:30:54 +01:00
|
|
|
"github.com/ncw/rclone/fs/sync"
|
2016-08-05 18:12:27 +02:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2017-11-27 12:42:02 +01:00
|
|
|
// Globals
|
|
|
|
var (
|
|
|
|
deleteEmptySrcDirs = false
|
|
|
|
)
|
|
|
|
|
2016-08-05 18:12:27 +02:00
|
|
|
func init() {
|
2016-10-22 13:05:45 +02:00
|
|
|
cmd.Root.AddCommand(commandDefintion)
|
2017-11-27 12:42:02 +01:00
|
|
|
commandDefintion.Flags().BoolVarP(&deleteEmptySrcDirs, "delete-empty-src-dirs", "", deleteEmptySrcDirs, "Delete empty source dirs after move")
|
2016-08-05 18:12:27 +02:00
|
|
|
}
|
|
|
|
|
2016-10-22 13:05:45 +02:00
|
|
|
var commandDefintion = &cobra.Command{
|
2016-08-05 18:12:27 +02:00
|
|
|
Use: "move source:path dest:path",
|
|
|
|
Short: `Move files from source to dest.`,
|
|
|
|
Long: `
|
|
|
|
Moves the contents of the source directory to the destination
|
2016-10-22 18:53:52 +02:00
|
|
|
directory. Rclone will error if the source and destination overlap and
|
|
|
|
the remote does not support a server side directory move operation.
|
2016-08-05 18:12:27 +02:00
|
|
|
|
|
|
|
If no filters are in use and if possible this will server side move
|
2016-10-23 18:34:17 +02:00
|
|
|
` + "`source:path`" + ` into ` + "`dest:path`" + `. After this ` + "`source:path`" + ` will no
|
2016-08-05 18:12:27 +02:00
|
|
|
longer longer exist.
|
|
|
|
|
2016-10-23 18:34:17 +02:00
|
|
|
Otherwise for each file in ` + "`source:path`" + ` selected by the filters (if
|
|
|
|
any) this will move it into ` + "`dest:path`" + `. If possible a server side
|
2016-08-05 18:12:27 +02:00
|
|
|
move will be used, otherwise it will copy it (server side if possible)
|
2016-10-23 18:34:17 +02:00
|
|
|
into ` + "`dest:path`" + ` then delete the original (if no errors on copy) in
|
|
|
|
` + "`source:path`" + `.
|
2016-08-05 18:12:27 +02:00
|
|
|
|
2017-11-27 12:42:02 +01:00
|
|
|
If you want to delete empty source directories after move, use the --delete-empty-src-dirs flag.
|
|
|
|
|
2016-08-05 18:12:27 +02:00
|
|
|
**Important**: Since this can cause data loss, test first with the
|
|
|
|
--dry-run flag.
|
2018-10-21 11:51:41 +02:00
|
|
|
|
|
|
|
**Note**: Use the ` + "`-P`" + `/` + "`--progress`" + ` flag to view real-time transfer statistics.
|
2016-08-05 18:12:27 +02:00
|
|
|
`,
|
|
|
|
Run: func(command *cobra.Command, args []string) {
|
|
|
|
cmd.CheckArgs(2, 2, command, args)
|
2018-05-07 19:13:17 +02:00
|
|
|
fsrc, srcFileName, fdst := cmd.NewFsSrcFileDst(args)
|
2016-12-04 17:52:24 +01:00
|
|
|
cmd.Run(true, true, command, func() error {
|
2018-05-07 19:13:17 +02:00
|
|
|
if srcFileName == "" {
|
|
|
|
return sync.MoveDir(fdst, fsrc, deleteEmptySrcDirs)
|
|
|
|
}
|
|
|
|
return operations.MoveFile(fdst, fsrc, srcFileName, srcFileName)
|
2016-08-05 18:12:27 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|