-
Notifications
You must be signed in to change notification settings - Fork 1
/
upmove.cmd
67 lines (67 loc) · 2.61 KB
/
upmove.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
@echo off & @rem based on XNT.kex script template version 2016-03-05
setlocal enableextensions & prompt @
if exist "%~2" goto MANY & @rem shell::sendto split
if not "%~2" == "" call "%~0" "%*"
if not "%~2" == "" goto DONE & @rem expect one argument
if "%~1" == "" goto HELP & @rem expect one argument
if "%~1" == "?" goto HELP & @rem missing switch char
if "%~1" == "/?" goto HELP & @rem minimal requirement
if "%~1" == "-?" goto HELP & @rem permit DOS SWITCHAR
:DOIT --------------------------------------------------------------
set THIS=%0
set FULL=%~f1
set NAME=%~nx1
set NEED=%FULL%
if not exist "%NEED%" goto NEED
set NEED=%~dp1..
for %%x in ("%FULL%\..\..") do set DEST=%%~fx
if "%~dp1" == "%DEST%" goto NEED
for %%x in ("%FULL%\..") do set NEED=%%~nxx
if "%~nx1" == "%NEED%" goto DEST
call :EXEC move /-Y "%FULL%" "%DEST%"
if errorlevel 1 goto WAIT
goto DONE
:DEST --------------------------------------------------------------
dir /A/B "%~dp1"|find /V /C ""|find "1">nul
if not errorlevel 1 goto WORK
echo Error: %0 found more than one "%NAME%\*" object
goto WAIT
:WORK --------------------------------------------------------------
call :EXEC cd /D "%DEST%"
if errorlevel 1 goto WAIT
call :EXEC move /-Y "%NAME%" "%NAME%.tmp"
if errorlevel 1 goto WAIT
call :EXEC move /-Y "%NAME%.tmp\%NAME%" "%DEST%"
if errorlevel 1 goto UNDO
call :EXEC rd "%NAME%.tmp"
if errorlevel 1 goto WAIT
goto DONE
:UNDO --------------------------------------------------------------
call :EXEC move /-Y "%NAME%.tmp" "%NAME%"
goto WAIT
:EXEC --------------------------------------------------------------
echo %*
%*>nul
if not errorlevel 1 goto DONE
echo Error: %THIS% got non-zero exit code %ERRORLEVEL%
goto DONE
:MANY --------------------------------------------------------------
call "%~0" "%~1"
shift /1
if not "%~1" == "" goto MANY
goto DONE
:NEED --------------------------------------------------------------
echo/
echo Error: %0 found no "%NEED%"
:HELP --------------------------------------------------------------
echo Usage: %0 FILE
echo/
echo Moves a FILE or directory to its grandparent ..\..
echo and can handle D:\PATH\TARGET\SOURCE\SOURCE cases
echo with a temporary D:\PATH\TARGET\SOURCE.tmp folder.
echo The script can be used in a shell::SendTo shortcut.
echo/
:WAIT if first CMD line option was /c ------------------------------
set NEED=usebackq tokens=2 delims=/
for /F "%NEED% " %%c in ('%CMDCMDLINE%') do if /I "%%c" == "c" pause
:DONE -------------- (Frank Ellermann, 2016) -----------------------