Posted by member 99 on 2004-08-28 05:21:11 link
A variation on this idea, this will look for every module (in a given folder) that you have more than one set of documentation for (eg, popup2-2.1.3, popup2-2.1.7 are both popup2) and move them to a new subdirectory named after that module:
@echo off
setlocal
if errorlevel 1 goto noluck
:: strip quotes
set ROOT=%1.
if %ROOT:~0,1%.%ROOT:~0,1%=="." set ROOT=%ROOT:~1,-1%
set ROOT=%ROOT:~0,-1%
:: ask for the root if we weren't told
if "%ROOT%"=="" (
set /P ROOT=Enter root folder or drag^&drop here:
)
:: strip quotes
set ROOT=%ROOT%.
if %ROOT:~0,1%.%ROOT:~0,1%=="." set ROOT=%ROOT:~1,-1%
set ROOT=%ROOT:~0,-1%
:: quit if they really aren't talking
if "%ROOT%"=="" goto :eof
pushd "%ROOT%"
if errorlevel 1 goto baddir
:: send the module names to :move, may get duplicates
for /F "tokens=1,2 delims=-" %%F in ('dir/b') do (
call :move %%F %%G
)
popd
goto :eof
:baddir
echo "%ROOT%"
goto :eof
:move
:: did it really have a -?
if "%2"=="" goto re-sort
set MODULE=%1
:: have we seen this guy before?
for /F "tokens=1 delims==" %%V in ('set') do (
if "%%V"=="%MODULE%" goto second_time
)
set %MODULE%=That's one...
goto :eof
:second_time
:: there's at least two of them, so put them in a subdir
:: make the section if it doesn't exist
if not exist "%MODULE%" md "%MODULE%"
:re-sort
:: brush your teeth
for /F %%H in ('dir/b "%MODULE%-*" 2^>NUL') do (
move "%%H" "%MODULE%" > NUL
)
goto :eof
:noluck
echo Sorry, your OS isn't special enough.
setlocal
if errorlevel 1 goto noluck
:: strip quotes
set ROOT=%1.
if %ROOT:~0,1%.%ROOT:~0,1%=="." set ROOT=%ROOT:~1,-1%
set ROOT=%ROOT:~0,-1%
:: ask for the root if we weren't told
if "%ROOT%"=="" (
set /P ROOT=Enter root folder or drag^&drop here:
)
:: strip quotes
set ROOT=%ROOT%.
if %ROOT:~0,1%.%ROOT:~0,1%=="." set ROOT=%ROOT:~1,-1%
set ROOT=%ROOT:~0,-1%
:: quit if they really aren't talking
if "%ROOT%"=="" goto :eof
pushd "%ROOT%"
if errorlevel 1 goto baddir
:: send the module names to :move, may get duplicates
for /F "tokens=1,2 delims=-" %%F in ('dir/b') do (
call :move %%F %%G
)
popd
goto :eof
:baddir
echo "%ROOT%"
goto :eof
:move
:: did it really have a -?
if "%2"=="" goto re-sort
set MODULE=%1
:: have we seen this guy before?
for /F "tokens=1 delims==" %%V in ('set') do (
if "%%V"=="%MODULE%" goto second_time
)
set %MODULE%=That's one...
goto :eof
:second_time
:: there's at least two of them, so put them in a subdir
:: make the section if it doesn't exist
if not exist "%MODULE%" md "%MODULE%"
:re-sort
:: brush your teeth
for /F %%H in ('dir/b "%MODULE%-*" 2^>NUL') do (
move "%%H" "%MODULE%" > NUL
)
goto :eof
:noluck
echo Sorry, your OS isn't special enough.