Hello Gurus,
I have script which will pull the filenames of a folder as "xyz01.csv". Then extracts the 2 digit before dot and creates folder of that name (Ex:01) .Then move the file into that new folder. Below is the one I wrote. Somehow the variable is not working correctly which gives the folder name incorrectly. I added the SetLocal function in the begin but does not help me.
Any help is highly appreciated.
Thanks,
@echo off
SetLocal EnableDelayedExpansion
cls
set SourceDir=C:\TEMp\WORK_TEST\INPUT\
set TargetDir= "C:\TEMp\WORK_TEST\OUTPUT\"
REM::: ------------CODE FOR CSV
for %%i in (%SourceDir%*.csv) do (
set var=%%i
set substr6=%var:~-6,-4%
echo !var[%%i]!
echo !substr6!
echo !substr6!---Extracts 6digits from end then remove the last 4
IF EXIST %TargetDir%%substr6% (
echo folder exists
move %%i %TargetDir%%substr6%
) ELSE (
echo folder do not
mkdir %TargetDir%%substr6%
move %%i %TargetDir%%substr6%
)
)