Creates a folder for each filename without the extension and then moves the file onto it.
For those that are into that sort of thing :)
@echo off
setlocal enabledelayedexpansion
rem Check if a parameter is provided
if "%~1"=="" (
echo No filename pattern specified ie: *.pdf
exit /b
)
rem Loop through each file matching the wildcard passed as a parameter
for %%f in (%1) do (
rem Get the file name without the extension and the file extension
set "filename=%%~nf"
set "extension=%%~xf"
rem Create a folder with the file name if it doesn't exist
if not exist "!filename!" (
mkdir "!filename!"
)
rem Set the destination path
set "destpath=!filename!\%%~nxf"
rem Check if the file already exists in the folder
if exist "!destpath!" (
set "suffix=a"
rem Loop to find the next available suffix
:find_suffix
set "newdest=!filename!\%%~nf-!suffix!%%~xf"
if exist "!newdest!" (
set /a "suffix=!suffix! + 1"
for %%i in (!suffix!) do (
set "suffix=!suffix:a=z!"
)
goto :find_suffix
)
rem Move the file with the suffix
move "%%f" "!newdest!"
) else (
rem Move the file without suffix if it doesn't exist
move "%%f" "!destpath!"
)
)
endlocal