Solved Copying Missing Files To A Good Directory Using Visual Basic

Dell Inspiron e1405, e1505, e1705 series...
July 16, 2012 at 15:32:31
Specs: Windows XP, 2GHz/2.00 GB
I need help with a project in Visual Basic. What I need done is to have a program copy files from one directory to another. But that's not just it! I need it to copy ONLY files that aren't already there. In other words, if folder "A" has files 1, 2, 3, 4, 5, 6, 7, and 8, and folder "B" has files 1, 2, 3, 4, and 5, I want it to copy from "A" to "B", files that it doesn't have like 6 and 7 and 8. But what I don't want is to have 1, 2, 3, 4, and 5 copied since it is ALREADY there! Can anyone please tell me the code that I need to have if I am copying from C:\test to C:\test2 (assuming that both folders have the same files except "test" has more files than "test2" and I only want to copy the extra files from "test") ?
Please write back ASAP!!! (As Simple As Possible) ;-)
I could either use VB or use Batch but I need an answer QUICK!!!

See More: Copying Missing Files To A Good Directory Using Visual Basic

Report •

July 16, 2012 at 18:48:00
✔ Best Answer
here's batch-based solution that might work:

dir /b sourcedir>source.txt
dir /b targdir>dest.txt
:this give names of only files that ARE NOT in dest.txt (ie: target directory)
:(i think..)
findstr /L /v /g:dest.txt source.txt>diff.txt

visbas can shell/ex this bat, then open the file diff.txt and go from there.
visbas could do this w/o batch, but why? it would involve more code, more memory, and probably more processing-time.

Report •

July 17, 2012 at 00:00:48
Possibly about the easiest way to do this:
Array.ForEach(IO.Directory.GetFiles(source), Sub(file)
  Dim destPath = IO.Path.Combine(destination, IO.Path.GetFileName(file))
  If Not IO.File.Exists(destPath) Then IO.File.Copy(file, destPath)
End Sub)

How To Ask Questions The Smart Way

Report •

Related Solutions

Ask Question