Be there or be square!
PowerShell, 59 62 61 60 bytes
$z=ls($d=$args)-di;('"+-+
| |
+-+"','mv b.ps1 "$d"')[$?]|iex
Try it online!
Explanation
PowerShell's Move-Item
cmdlet (mv
) renames a file as well, so giving it a directory that doesn't exist as the destination just renames the file to that last component instead (as long as the parent exists), so that was no good.
I could use Test-Path
to determine that the destination exists and is a directory, but it's too long Test-Path $d -PathT C
.
So instead I'm using Get-ChildItem
(ls
) with the (shortened) -Directory
parameter, and checking $?
to see if it was successful. The output if there is any is assigned to $z
so that it isn't seen.
That's done in the form of an array with 2 elements, then indexing into the array with the boolean value of $?
, which will get coalesced to 0
or 1
, so the first array element is chosen if the destination directory doesn't exist, and second if it does.
The first array element is a string containing the box (quoted); newlines are allowed in strings, even when they're not heredocs. The second element is a string containing the move command.
The result of that array selection gets piped into Invoke-Expression
(iex
) to be executed. This is necessary because of I just leave the actual move command in the array, it gets executed no matter what (to populate the array), which defeats the purpose.
Octave, 60 57 52 bytes
8 bytes saved thanks to @Stewie
if~movefile('f.m',input(''))disp("+-+\n| |\n+-+")end
This is a script that lives within a file called f.m
. When run, it will prompt the user for the folder to move the file to. If the folder does not exist and the move operation fails, then movefile
returns false
(or 0
) otherwise it returns true
(or 1
). If it's false
, we display the string "+-+\n| |\n+-+"
.
Batch, 80 bytes
@if not "%1"=="" move %0 %1\>nul 2>nul&&%1\%~nx0||(echo +-+&echo ^| ^|&echo +-+)
Batch doesn't like it if you move the batch file as it's running, so by invoking %1\%~nx0
(which is the new name of the batch file) Batch stops looking for the old batch file.