Solved

batch script for creating folders and moving files

Posted on 2011-02-23
1
288 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 53

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Deleting files if over certain number of days old (forfiles?) 4 56
How to combine txt files and change .txt extension 7 62
Internet Connection Util 8 102
move command 5 62
Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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