Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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:\folder3dir /B /O %dirA% >dirA.txt
dir /B /O %dirB% >dirB.txtEcho 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=%%Bfor /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)
EXITbut I want to copy the files that begin only with a perticular suffix
Please help me.....ASAP

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/

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

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.

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

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'

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

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

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 felicityM2

Dear forum members..... Please accept my apologies....I never wanted to offend anyone in any way....
Thank you very very much.... I got it..

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |