Last active
August 29, 2015 14:20
-
-
Save privatmamtora/44ce0117f4546b77eaa4 to your computer and use it in GitHub Desktop.
Moves all files to root. Will not move duplicates. Removes leftover empty folders.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: Name: MoveUp.cmd | |
:: Purpose: Moves all files to root. Will not move duplicates. Removes leftover empty folders. | |
:: Author: privat.mamtora@gmail.com | |
:: Version: 1.1 | |
:: Revision: May 2015 - initial version | |
:: Revision: May 2015 - Fixed issue 1# directory special character issues with ROBOCOPY | |
:: Revision: May 2015 - Fixed issue 2# Directory with exclamation marks | |
:: Revision: Jun 2015 - Fixed filenames with & | |
:: Revision: Jun 2015 - Migrate to use "Send To" menu, allows for multiple select by single process | |
@echo off | |
SETLOCAL ENABLEEXTENSIONS | |
SET me=%~n0 | |
SET parent=%~dp0 | |
REM if not -%1-==-- echo Argument one provided | |
if -%1-==-- echo Argument one not provided & exit /b | |
FOR %%A IN (%*) DO ( | |
FOR /f "delims=" %%G IN ('dir %%A /s /b /o:gn /a:d^|sort /r') DO ( | |
CALL :moveDir "%%G" | |
) | |
) | |
GOTO :END | |
::----- start Function moveDir ----- | |
:moveDir | |
@echo off | |
set src="%~1\." | |
set dest="%~1\.." | |
ROBOCOPY %src% %dest% /MOV /NS /NC /NFL /NDL /NP /NJH /NJS > nul | |
( dir /b /a %src% | findstr . ) > nul && ( | |
REM echo %src% non-empty | |
) || ( | |
REM echo %src% empty | |
RD %src% | |
) | |
GOTO :eof | |
::----- end Function moveDir ----- | |
::----- End Script | |
:END | |
PAUSE | |
ENDLOCAL | |
ECHO ON | |
@EXIT /B 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment