Just how can I "invert" a directory site framework?
I make use of a photo handling device which can set result various dimensions of the very same photo right into the directory site kind:
<specific directory>\<image size name>
e.g. SuperBowl\Fullsize JPEG
I would love to consistently invert this and also relocate any kind of documents within the subfolder to the new area, i.e. :
<image size name>\<specific directory>
e.g. Fullsize JPEG\SuperBowl
I would certainly imagine running the procedure versus the Superbowl
folder. Exists a straightforward device readily available that can do this, or a Windows.bat or Linux celebration script?
Hafthor is 2nd and also 3rd lines near sufficient suffice, yet I intended to have the ability to define a directory so changed them to be:
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"
Actually, I went a reasonable little bit more and also create the adhering to script - I take no duty whatsoever for any kind of quirkiness/ undesirable removal of documents that might take place ; go for your very own threat:
@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
I do not recognize set scripting, yet this is possibly the basic procedure you would certainly intend to make use of:
- Create an exterior folder for each and every dimension folder.
- Relocate each dimension folder to the exterior directory site, relabeling it to the name of its moms and dad (the details directory site name).
And also, uh ... that's it, I presume. Not also intricate in the meantime.
I assume something similar to this needs to function:
for /d %x in (*) do for /d %y in ("%x\*") do md "%~ny"
for /d %x in (*) do for /d %y in ("%x\*") do md "%~ny\%x"
for /d %x in (*) do for /d %y in ("%x\*") do move "%x\%~ny\*" "%~ny\%x"
The first 2 lines create the upside down directory site set, the 3rd actions every little thing. If you place this in a set documents, you require to double the % personalities.
Pretty sure you do not require the first line as MKDIR appears to create intermediate directory sites instantly, yet I do not given that how much time.
Related questions