I have few file that need to be organize by month into new folder that created by the filename that contain string & number.
example file :
Cycle2006_P.zip
Cycle2307_P.zip
Cycle2410_P.zip
Result:
Jun\Cycle2006_P.zip
Jul\Cycle2307_P.zip
Oct\Cycle2410_P.zip
Here what I tried. But the result are different. The script only capture Cycle2410_P.zip and create Oct folder only.
Result :
Oct\Cycle2006_P.zip
\Cycle2307_P.zip
\Cycle2410_P.zip
@echo off
Set filename=D:\Users\AALADELA\Desktop\pbilsr01\*.zip*
For %%A in ("%filename%") do (
Set Folder=%%~dpA
Set Name=%%~nxA
)
REM get the 7th string from filename and set into %month% e.g. 06 = Jun
set month=%Name:~7,2%
if %month%==01 set currentmonthfolder=Jan
if %month%==02 set currentmonthfolder=Feb
if %month%==03 set currentmonthfolder=Mar
if %month%==04 set currentmonthfolder=Apr
if %month%==05 set currentmonthfolder=May
if %month%==06 set currentmonthfolder=Jun
if %month%==07 set currentmonthfolder=Jul
if %month%==08 set currentmonthfolder=Aug
if %month%==09 set currentmonthfolder=Sep
if %month%==10 set currentmonthfolder=Oct
if %month%==11 set currentmonthfolder=Nov
if %month%==12 set currentmonthfolder=Dec
:Move
@echo off
echo.
echo Move File to New Location
mkdir "D:\Users\AALADELA\Desktop\Backup\%currentmonthfolder%"
Move "D:\Users\AALADELA\Desktop\pbilsr01\*.zip*" "D:\Users\AALADELA\Desktop\Backup\%currentmonthfolder%"
set RESULT=%ERRORLEVEL%
if %RESULT% equ 0 (
echo.
echo Success Move
GOTO Copi
) else (
echo Error. Retry. . . .
TIMEOUT /T 5 >nul
GOTO Move
)
pause