Computing.Net > Forums > Programming > copy files from folder A to folder B ....

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

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

Reply to Message Icon

Name: master_mzee
Date: October 21, 2009 at 21:45:25 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Fist (by fmwap)
Date: October 21, 2009 at 22:05:34 Pacific
Reply:

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/


0

Response Number 2
Name: Fist (by fmwap)
Date: October 21, 2009 at 22:10:23 Pacific
Reply:

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


0

Response Number 3
Name: Fist (by fmwap)
Date: October 21, 2009 at 22:16:29 Pacific
Reply:

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.


0

Response Number 4
Name: master_mzee
Date: October 21, 2009 at 22:29:53 Pacific
Reply:

sorry guys for the last but one sentence ... It should be the files with a particular suffix


0

Response Number 5
Name: master_mzee
Date: October 21, 2009 at 22:33:11 Pacific
Reply:

hi fist,

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


0

Related Posts

See More



Response Number 6
Name: Fist (by fmwap)
Date: October 21, 2009 at 22:40:12 Pacific
Reply:

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'


0

Response Number 7
Name: master_mzee
Date: October 21, 2009 at 23:11:18 Pacific
Reply:

Thanx Fist,

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


0

Response Number 8
Name: Fist (by fmwap)
Date: October 21, 2009 at 23:48:32 Pacific
Reply:

Yup, totally free.

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


0

Response Number 9
Name: Mechanix2Go
Date: October 24, 2009 at 02:34:30 Pacific
Reply:

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


1

Response Number 10
Name: master_mzee
Date: October 24, 2009 at 04:34:43 Pacific
Reply:

Dear forum members..... Please accept my apologies....I never wanted to offend anyone in any way....

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


0

Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: copy files from folder A to folder B ....

script to copy files from a server www.computing.net/answers/programming/script-to-copy-files-from-a-server-/16825.html

Copying files from one driver hive to another www.computing.net/answers/programming/copying-files-from-one-driver-hive-to-another/18970.html

Copy files from mult. subfolders www.computing.net/answers/programming/copy-files-from-mult-subfolders/13105.html