File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
src/main/java/com/mycmd/commands Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .mycmd .commands ;
2+
3+ import com .mycmd .Command ;
4+ import com .mycmd .ShellContext ;
5+ import java .io .File ;
6+ import java .io .IOException ;
7+ import java .nio .file .*;
8+
9+ public class MoveCommand implements Command {
10+ @ Override
11+ public void execute (String [] args , ShellContext context ) throws IOException {
12+ if (args .length < 2 ) {
13+ System .out .println ("Usage: move <source> <destination>" );
14+ return ;
15+ }
16+
17+ Path source = context .resolvePath (args [0 ]).toPath ();
18+ Path destination = context .resolvePath (args [1 ]).toPath ();
19+
20+ if (!Files .exists (source )) {
21+ System .out .println ("The system cannot find the file specified." );
22+ return ;
23+ }
24+
25+ try {
26+ Files .move (source , destination , StandardCopyOption .REPLACE_EXISTING );
27+ System .out .println ("Moved: " + source .getFileName () + " -> " + destination );
28+ } catch (IOException e ) {
29+ System .out .println ("Error moving file: " + e .getMessage ());
30+ }
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments