Link to home
Start Free TrialLog in
Avatar of failed
failed

asked on

batch script for creating folders and moving files

I have files with a name in the format of -> 12345678_ordrsp.test
What I am trying to do is take the first 8 characters "12345678" which would be custno
and the characters 10-15 "ordrsp" which would be messagetype.

I would then copy the file to one folder and then move the original file to another.

My code so far:

setlocal EnableDelayedExpansion

dir /b c:\edi_out\*.xml > filelist.txt

pushd c:\edi_out

REM append .xml to all files
rename *_*.* *.*.xml

for /F "tokens=*" %%F in (filelist.txt) do (
   set str=%%F
   set custno=%str:~0,8%
   set messagetype=%str:~10,15%

   echo %custno
xcopy "%%~F" "C:\backup\%custno%\%messagetype%"
move "%%~F" "C:\%custno%\%messagetype%"
)
popd
pause
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial