Page 1 of 1

move Files from different folders

Posted: 11 Apr 2008 11:23
by prashob12
Hello

i need to create a batch file to copy xml files from different folders in the same directory
for e.g.
The path:

D:\PRASHOB\LY-01\jurion\test3\New\output1\XML

contains around 750 folders each contains some xml files.

now each folder may contain xml files maximum of five different types.

i.e.
1) kg_2007-04-12_8-u-76-06_jurion.xml (*_jurion.xml)
2) kg_2007-04-12_8-u-76-06_vt.xml (*_vt.xml)
3) kg_2007-04-12_8-u-76-06_cas_ur.xml (*_cas*.xml)
4) kg_2007-04-12_8-u-76-06_pm.xml (*_pm.xml)
5) kg_2007-04-12_8-u-76-06_lsa.xml (*_ls*.xml)

now here i want to move each type of xml files from each folder to its respective folders:


FOLDER NAME
*_jurion.xml move to jurion
*_vt.xml - vt
*_pm.xml - pm
*_cas*.xml -cas
*_ls*.xml -ls

the batch file should go to the folder take out the xml file from that folder and move it to the respective folder mentioned above.

I also encounter problem if the file naming is too long

Please help me in this.


Regards
Prashob

Posted: 17 Jul 2008 10:46
by greenfinch
Hi Prashob,

save this as something.cmd in D:\PRASHOB\LY-01\jurion\test3\New\output1\XML and run it

I assume that your target folders already exist (i.e. jurion, vt, pm, cas, ls)

Code: Select all

setlocal

REM targetpath contains folders jurion, vt, pm, cas, ls
set targetpath=d:\temp

FOR /f "delims=" %%f in ('dir /ad /b') do (call :main "%%f")
GOTO end

:main
pushd %1
move "*_jurion.xml" %targetpath%\jurion
move "*_vt.xml" %targetpath%\vt
move "*_pm.xml" %targetpath%\pm
move "*_cas*.xml" %targetpath%\cas
move "*_ls*.xml" %targetpath%\ls
popd
GOTO:EOF

:end