Solved

batch script for creating folders and moving files

Posted on 2011-02-23
1
267 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:failed
1 Comment
 
LVL 51

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 34966509
I think this does what you are looking for:

@echo off
for %%A in ("c:\edi_out\*.xml) do (
  for /F "tokens=1-2 delims=._" %%B in ("%%A") do (
    copy "%%A" "c:\backup\%%B\%%C\%%~nxA.xml"
    move "%%A" "c:\%%B\%%C\%%~nxA.xml"
  )
)

Open in new window

~bp
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now