Skip to content

Instantly share code, notes, and snippets.

@privatmamtora
Last active August 29, 2015 14:20
Show Gist options
  • Save privatmamtora/44ce0117f4546b77eaa4 to your computer and use it in GitHub Desktop.
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.
:: 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