As segundas e terceiras linhas de Hafthor perto o suficiente, mas eu queria ser capaz de especificar um diretório para modificá-las:
for /d %%x in ("%1") do for /d %%y in ("%%x\*") do md "%%~ny\%%x"
for /d %%x in ("%1") do for /d %%y in ("%%x\*") do move "%%x\%%~ny\*" "%%~ny\%%x"
Na verdade, fui um pouco além e desenvolvi o seguinte script - não me responsabilizo por qualquer estranheza / exclusão indesejada de arquivos que possam ocorrer; corra por sua conta e risco:
@echo off
if [%1]==[] goto noparameter
if "%1"=="*" goto nowildcards
if "%1"=="/?" goto help
if not exist %1 (
echo The directory does not exist.
goto exit
)
echo.
echo Creating new directories...
for /d %%x in ("%1") do for /d %%y in ("%%x\*") do md "%%~ny\%%x"
echo.
echo Moving files...
for /d %%x in ("%1") do for /d %%y in ("%%x\*") do move "%%x\%%~ny\*" "%%~ny\%%x"
echo.
echo Files were flipped for directory %1; this directory now contains (should be empty):
dir %1 /S /B
echo.
echo =======================================================================
echo The previous (sure it's empty?) directory structure will now be deleted
echo.
if "%2"=="/F" (
echo Deletion forced
rmdir %1 /S /Q
) else (
rmdir %1 /S
)
goto exit
:noparameter
echo You must specify a directory to flip.
goto exit
:nowildcards
echo You cannot use a wildcard (asterisk) with this script.
goto exit
:help
echo Takes directory structure a/b and converts it to b/a, moving any files within.
echo Works only with a single directory when you are within its parent.
echo.
echo FLIP [directory] [/F]
echo.
echo. /F Force deletion of directory structure without prompt
goto exit
:exit