1#!
2#[[BEGIN PROPERTIES]]
3# Type = Command
4# Order = 7.0
5# Interpreter = perl
6# Caption = Move
7# Descr =Move one or more files and/or directories into another
8# Descr =directory.
9# Descr =
10# Descr =Selection details:
11# Descr =
12# Descr =  Source: The files and directories to be moved.
13# Descr =
14# Descr =  Target: The target directory, or a single target file
15# Descr =          to be overwritten by a single source file.
16# Icon = move_file.tga
17# Hotkey = Ctrl+M
18#[[END PROPERTIES]]
19
20use strict;
21use warnings;
22BEGIN { require "$ENV{'EM_DIR'}/res/emFileMan/scripts/cmd-util.pl"; }
23
24if (IsFirstPass()) {
25
26	ErrorIfNoSources();
27	ErrorIfNotSingleTarget();
28	ErrorIfRootSources();
29
30	ConfirmIfSourcesAcrossDirs();
31
32	my $message=
33		"Are you sure to move, overwriting any existing target files?\n".
34		"\n".
35		"From:\n".
36		GetSrcListing().
37		"\n".
38		"To:\n".
39		GetTgtListing()
40	;
41	Confirm("Move",$message);
42
43	SecondPassInTerminal("Move");
44}
45
46my @src=GetSrc();
47my @tgt=GetTgt();
48
49my $e=TermRunAndSync(
50	"mv",
51	($Config{'osname'} eq 'linux' or $Config{'osname'} eq 'cygwin') ? (
52		"-vf"
53	)
54	: (
55		"-f"
56	),
57	"--",
58	@src,
59	$tgt[0]
60);
61
62my @newTgt=();
63if (-d $tgt[0]) {
64	for (my $i=0; $i<@src; $i++) {
65		my $f=fileparse($src[$i]);
66		my $p=catfile($tgt[0],$f);
67		if (-e $p) {
68			push(@newTgt,$p);
69		}
70	}
71}
72if (@newTgt > 0) {
73	SendSelectKS(@newTgt);
74}
75else {
76	SendUpdate();
77}
78
79TermEnd($e);
80