
The answer considers this comment: This only works if there is a space after the number. I need something that will always count the first 5 digits and go off of that. - @Brandon Hurst
So, my limited English not help to explain this code and the mechanic apply here to do this job...
Well, basically, this take files out in dir command and get the five 1st characters to echo in unicode format/layout by cmd/u and using the findstr filter for to get only numbers, after, check if folder match/exist, in case positive, this code will copy this files to a same folder where five 1st string...
@echo off && setlocal EnableDelayedExpansion & title <nul & call title ..\%~nx0
cd/d "%~dp0" && for /f tokens^=*eol^=* %%i in ('dir /b/a:-d .\*.* ^|find/v "%0"
')do set "_f=%%~ni" && set "_fc=%%~fi" && set "_N=" && set "_at5=!_f:~,5!" && (
for /f %%N in ('cmd /u/c "echo=!_at5!^<nul|findstr [0-9]"')do set "_N=!_N!%%~N"
if exist "!_N!\." echo=!_fc! ^> .\!_N!\%%~nxi &cmd/v/cmove "!_fc!" "!_N!\">nul)
rem./ you can put/do some more tasks here in your bat... && endlocal && exit /b
G:\SUPER_USER\Q1507690\54321testX.pdf > .\54321\54321testX.pdf
G:\SUPER_USER\Q1507690\54321-test.jpg > .\54321\54321-test.jpg
G:\SUPER_USER\Q1507690\12345 test.jpg > .\12345\12345 test.jpg
G:\SUPER_USER\Q1507690\12345,test.pdf > .\12345\12345,test.pdf
G:\SUPER_USER\Q1507690\12346 test.jpg > .\12346\12346 test.jpg
G:\SUPER_USER\Q1507690\12346.test.pdf > .\12346\12346.test.pdf
G:\SUPER_USER\Q1507690\12346_test.jpg > .\12346\12346_test.jpg
Obs.: I´ll try update when some friends help me with English, so, really sorry my limited English...
cd/d "%~dp0"´to the full path to folder.. – Io-oI Dec 12 '19 at 22:05