-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2-2-subdir2dir.cmd
62 lines (51 loc) · 1.52 KB
/
2-2-subdir2dir.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
color 0a & title subdir 2 dir
for /D %%D in ("%cd%\*") do call :FOR_DIR "%%~D"
exit
:FOR_DIR
set "dirName=%~nx1"
for /f "usebackq tokens=* delims=" %%F in (`dir "%~1\*" /b/a-d`) do call :FOR_FILE "%~1\%%~F"
for /f "usebackq tokens=* delims=" %%D in (`dir "%~1\*" /b/ad `) do call :FOR_DIR2 "%~1\%%~D"
rmdir %1
exit /B
:FOR_FILE
call :createUniqueName %1 newName
MOVE /-Y "%~f1" "%cd%\%newName%%~x1" || (
echo.MOVE "%~f1" "%cd%\%newName%%~x1">"error.txt"
exit /B 1
)
::Zeile zum Anfang der changes.log hinzufuegen
copy changes.log _changes.log
echo "%dirName%\%~nx1"$MOVED_TO;"%newName%%~x1">changes.log
copy /B changes.log + _changes.log changes.log
del _changes.log
exit /B 0
:createUniqueName
set "%~2=%~n1"
if not exist "%~nx1" exit /B 0
set /a i=0
:_createUniqueName
set /a i+=1
if exist "%~n1 (%i%)%~x1" goto _createUniqueName
set "%~2=%~n1 (%i%)"
exit /b %i%
:FOR_DIR2
call :createUniqueFolderName %1 newName
MOVE /-Y "%dirName%\%~nx1" "%cd%\%newName%" || (
echo.MOVE "%dirName%\%~nx1" "%cd%\%newName%">"error.txt"
exit /B 1
)
::Zeile zum Anfang der changes.log hinzufuegen
copy changes.log _changes.log
echo "%dirName%\%~nx1"$MOVED_TO;"%newName%">changes.log
copy /B changes.log + _changes.log changes.log
del _changes.log
exit /B 0
:createUniqueFolderName
set "%~2=%~nx1"
if not exist "%~nx1" exit /B 0
set /a i=0
:_createUniqueFolderName
set /a i+=1
if exist "%~nx1 (%i%)" goto _createUniqueFolderName
set "%~2=%~1 (%i%)"
exit /b %i%