1#!
2#[[BEGIN PROPERTIES]]
3# Type = Command
4# Order = 8.0
5# Interpreter = perl
6# Caption = Move As
7# Descr =Move a single file or directory into any directory while giving it
8# Descr =another name. The name is asked.
9# Descr =
10# Descr =Selection details:
11# Descr =
12# Descr =  Source: The file or directory to be moved and renamed.
13# Descr =
14# Descr =  Target: The target directory into which the file or directory
15# Descr =          shall be moved.
16# Icon = move_file_as.tga
17# Hotkey = Meta+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	ErrorIfNotSingleSource();
27	ErrorIfNotSingleTarget();
28	ErrorIfTargetsNotDirs();
29	ErrorIfRootSources();
30
31	my @src=GetSrc();
32	my $oldPath=$src[0];
33	my ($oldName, $oldDir)=fileparse($oldPath);
34	my @tgt=GetTgt();
35	my $newDir=$tgt[0];
36
37	my $newName=FilenameEdit(
38		"Move As",
39		"Please enter a name for a movement of\n\n  $oldPath\n\ninto\n\n  $newDir",
40		$oldName
41	);
42
43	if (-e catfile($newDir,$newName)) {
44		Error("A file or directory with that name already exists.");
45	}
46
47	SetFirstPassResult($newName);
48
49	SecondPassInTerminal("Move As");
50}
51
52my @src=GetSrc();
53my $oldPath=$src[0];
54my @tgt=GetTgt();
55my $newDir=$tgt[0];
56my $newName=GetFirstPassResult();
57my $newPath=catfile($newDir,$newName);
58
59my $e=TermRunAndSync(
60	"mv",
61	($Config{'osname'} eq 'linux' or $Config{'osname'} eq 'cygwin') ? (
62		"-vf"
63	)
64	: (
65		"-f"
66	),
67	"--",
68	$oldPath,
69	$newPath
70);
71
72if (-e $newPath) {
73	SendSelectKS($newPath);
74}
75else {
76	SendUpdate();
77}
78
79TermEnd($e);
80