Solved

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

Posted on 2007-04-05
12
328 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
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 …

679 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