How to copy a file?
-
Hi, I need to write a program which can copy a file simply from a source folder to a destination folder. Please include the codes for a simple program doing so.
-
Hi, I need to write a program which can copy a file simply from a source folder to a destination folder. Please include the codes for a simple program doing so.
Below is the sample VB.NET Code. Hope you can convert it easily using C#.
using System.IO
Public Sub CopyDir(ByVal strSrc As String, ByVal strDest As String)
Dim dirInfo As New DirectoryInfo(strSrc)
Dim fsInfo As FileSystemInfo
If Not Directory.Exists(strDest) Then
Directory.CreateDirectory(strDest)
End If
For Each fsInfo In dirInfo.GetFileSystemInfos
Dim strDestFileName As String = Path.Combine(strDest, fsInfo.Name)
If TypeOf fsInfo Is FileInfo Then
File.Copy(fsInfo.FullName, strDestFileName, True)
'This will overwrite files that already exist
Else
CopyDir(fsInfo.FullName, strDestFileName)
End If
Next
End SubSource : http://abhijitjana.blogspot.com/2007/10/copy-files-from-one-directory-to.html[^]
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
-
Hi, I need to write a program which can copy a file simply from a source folder to a destination folder. Please include the codes for a simple program doing so.
use System.IO.File.Copy(src,dest) where src and dest are source and target respectively. :) :)
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Microsoft Bing MAP using Javascript
CLR objects in SQL Server 2005
Uncommon C# Keywords/xml> -
Below is the sample VB.NET Code. Hope you can convert it easily using C#.
using System.IO
Public Sub CopyDir(ByVal strSrc As String, ByVal strDest As String)
Dim dirInfo As New DirectoryInfo(strSrc)
Dim fsInfo As FileSystemInfo
If Not Directory.Exists(strDest) Then
Directory.CreateDirectory(strDest)
End If
For Each fsInfo In dirInfo.GetFileSystemInfos
Dim strDestFileName As String = Path.Combine(strDest, fsInfo.Name)
If TypeOf fsInfo Is FileInfo Then
File.Copy(fsInfo.FullName, strDestFileName, True)
'This will overwrite files that already exist
Else
CopyDir(fsInfo.FullName, strDestFileName)
End If
Next
End SubSource : http://abhijitjana.blogspot.com/2007/10/copy-files-from-one-directory-to.html[^]
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
If you keep writing their code for them the will pass the exams, and one day you may end you having to mantain some of their code - even worse, I may end up having to fix it :) Give a hint, but please refrain from giving code for something as trivial as this otherwise they will never learn that one of the more important aspects of development is learning how to work things out for yourself. I mean, how difficult is it to go to google and put in file copy c# and look at the top few of the 815,000 hits.
Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP
-
If you keep writing their code for them the will pass the exams, and one day you may end you having to mantain some of their code - even worse, I may end up having to fix it :) Give a hint, but please refrain from giving code for something as trivial as this otherwise they will never learn that one of the more important aspects of development is learning how to work things out for yourself. I mean, how difficult is it to go to google and put in file copy c# and look at the top few of the 815,000 hits.
Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP
Ashfield wrote:
Give a hint,
Most of the cases I did the same. Just give the hint so that they can take it forward.
Ashfield wrote:
how difficult is it to go to google and put in file copy c# and look at the top few of the 815,000 hits.
I do the same ;) and Got the link from my Old Blog and I put it over here.
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.