Solved

Copy Directory, Sub directories and all files from local drive to network.

Posted on 2007-04-05
12
303 Views
Last Modified: 2013-11-26
OK, I have spent too long searching for a good answer to this one...

Using VB.NET, Visual Studio 2005.

Need a SIMPLE function that I can call to copy the contents from a directory (including files and subdirectories and files) on the local drive to a networked drive...permissions etc not an issue.
Overwrites etc ok, but maybe an option to check for duplicates and only copy unique would be nice.

Also need another function to delete the contents of the local directory if necessary.

Thanks
Michael
0
Comment
Question by:webkiwi1
  • 5
  • 4
  • 3
12 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 18860824
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18860881
Use My.Computer.FileSystem.MoveDirectory():
http://msdn2.microsoft.com/en-us/library/519wkbx1.aspx

Something like...

    My.Computer.FileSystem.MoveDirectory("c:\test1", "c:\test2", Microsoft.VisualBasic.FileIO.UIOption.AllDialogs)
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18860894
The VB.Net 2005 MoveDirectory() is natively "recursive".
0
 

Author Comment

by:webkiwi1
ID: 18860950
Sirbounty, you are a scholar and a gentleman...I think!
Thanks for the quick response, worked perfect...points awarded!

Thanks for the info Idle Mind.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18860972
If you're just moving files without any extra rules/processing then you're doing way too much work!...
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18861173
Thanx...but now that I've seen Idle_Mind's suggestion, I'm inclined to think that may have been a better option for you...?  Though I'm not sure exactly what you're trying to accomplish...
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:webkiwi1
ID: 18861223
Not sure about too much work, I cut and paste the code given to me by SirBounty and it worked...seemed pretty simple!

I will keep the MSDN stuff handy, but at this point do not have the time to work through it and figure it out. Iasked for a simple founction and got what I asked for, which was the ability to copy a folder, files, sub directories and files to a netowrk drive, and only copy new files.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18861236
Glad I could assist you. :^)
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18861320
Whatever floats your boat...   =)

There isn't anything to "figure out" really though.  It's a "one liner" just like I showed:

    My.Computer.FileSystem.MoveDirectory(yourSourceFolderHere, yourTargetFolderHere)

That's LITERALLY it.

The vesion I gave above in my previous posts has the extra flag that shows the default windows operating system progress dialog while the files are moved.

Good luck...  =)
0
 

Author Comment

by:webkiwi1
ID: 18861359
Thanks Idle Mind, the progress dialog would be a great feature. I appreciate you taking the time to provide the example in a simple one liner like you last post. THAT is what I needed. I will have to try it out.

Microsoft do not make things simple and whenever I get sent to a MSDN page it can mean a lot of time figuring out options, syntax etc etc.

Do I need to import anything with your solution or will it work as is?
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18861403
It should work "as is".

...and I agree, the MSDN pages are sometimes hard to read and interpret.  =)

By the way, the "My.xxx.yyy" functions are NEW in VB.Net 2005.
0
 

Author Comment

by:webkiwi1
ID: 18863531
Awesome, I will give it a shot. Thanks and have a safe holiday weekend!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now