copy files from folder A to folder B ....

October 21, 2009 at 21:45:25
Specs: Windows XP
Hi gurus,

I need to write a batch script to copy the files from first folder, that begin with a perticular string (say begin with test, having files test1, test 2 etc) to folder B.
We need to copy all the files that are not present in folder B but present in folder A.

to copy the delta files from folder A to Folder B I have the script as ....

setlocal ENABLEDELAYEDEXPANSION
Set dirA=D:\folder2
Set dirB=D:\folder3

dir /B /O %dirA% >dirA.txt
dir /B /O %dirB% >dirB.txt

Echo Files that are found in folder %dirA% but NOT in folder %dirB% >AnotinB.txt
Echo. >>AnotinB.txt
find /V /C "this_is_an_absurd_string" dirB.txt >numlines.txt
for /f "tokens=3 delims= " %%B in (numlines.txt) do set /A maxnum=%%B

for /F "tokens=* delims= " %%A in (dirA.txt) do (
find /V /C "%%A" dirB.txt >numlines.txt
for /f "tokens=3 delims= " %%B in (numlines.txt) do set /A foundnum=%%B
if %maxnum%==!foundnum! echo %%A >>AnotinB.txt
)
copy /B AnotinB.txt dupli.txt >nul
more dupli.txt
for %%A in (dirA.txt dirB.txt AnotinB.txt BnotinA.txt numlines.txt) do (
if exist %%A del %%A
)

FOR /F %%i IN (D:\dupli.txt) do (copy "%dirA%"\%%i "%dirB%"\%%i)
EXIT

but I want to copy the files that begin only with a perticular suffix

Please help me.....ASAP


See More: copy files from folder A to folder B ....

Report •


#1
October 21, 2009 at 22:05:34
I dunno about BATCH but you could do this in one line w/ rsync (cwRsync on windows):

rsync -avz --include "test*" --exclude "*" /path/to/src/ /path/to/dst/


Report •

#2
October 21, 2009 at 22:10:23
Er, on second thought - that would copy the file from src even if it existed in dst

there's probably an option to do what you're asking though


Report •

#3
October 21, 2009 at 22:16:29
That would be the --ignore-existing option.

Try it first with -n (dry run) to only list files that would be copied w/o actually doing anything. Once it looks right, take out -n.


Report •

Related Solutions

#4
October 21, 2009 at 22:29:53
sorry guys for the last but one sentence ... It should be the files with a particular suffix

Report •

#5
October 21, 2009 at 22:33:11
hi fist,

is the rsync a a dos command to embed in a batch script....I am sorry I could not find it...


Report •

#6
October 21, 2009 at 22:40:12
Yup - it's command line only. You can grab it over here:

http://sourceforge.net/projects/ser...

Get the 'Installer' package - you wouldn't need the server package.

and no problem w/ the suffix, just change the --include directive: --include '*suffix'


Report •

#7
October 21, 2009 at 23:11:18
Thanx Fist,

I will try it out... Just one small question.... is it a freeware or do I need to pay for it..?


Report •

#8
October 21, 2009 at 23:48:32
Yup, totally free.

It's actually licensed under the GPL so any modifications / derived works must also be released as free software.


Report •

#9
October 24, 2009 at 02:34:30
If you don't follow through on your thread you will soon wear out the patience of those best able to help.

From your new thread:

"I need to write a batch script to copy the files with a particular suffix that are in Folder A but Not in Folder B.... I cannot use copy or Xcopy since I do not want to over write the files...and the process needs to be automated..ie. I am calling this script in a scheduler program... Also, is there any way to make a list of files copied from folder A to Folder B when the script is run..."

You can use copy and xcopy if you use them correctly.

xcopy A:\*suf.* B:\/d/y >> log


=====================================
Helping others achieve escape felicity

M2


Report •

#10
October 24, 2009 at 04:34:43
Dear forum members..... Please accept my apologies....I never wanted to offend anyone in any way....

Thank you very very much.... I got it..


Report •


Ask Question