Created
February 10, 2017 09:50
-
-
Save margani/38e51bbda81603a3d81aba648f4faea6 to your computer and use it in GitHub Desktop.
This code is for io programming in sync and async modes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string StartDirectory = @"D:\temp\source"; | |
string EndDirectory = @"D:\temp\destination"; | |
private async void btnStartAsync_Click(object sender, EventArgs e) | |
{ | |
foreach (string filename in Directory.EnumerateFiles(StartDirectory)) | |
{ | |
using (FileStream SourceStream = File.Open(filename, FileMode.Open)) | |
{ | |
var destFilePath = EndDirectory + filename.Substring(filename.LastIndexOf('\\')); | |
using (FileStream DestinationStream = File.Create(destFilePath)) | |
{ | |
await SourceStream.CopyToAsync(DestinationStream); | |
} | |
} | |
} | |
} | |
private void btnStartSync_Click(object sender, EventArgs e) | |
{ | |
foreach (string filename in Directory.EnumerateFiles(StartDirectory)) | |
{ | |
using (FileStream SourceStream = File.Open(filename, FileMode.Open)) | |
{ | |
using (FileStream DestinationStream = File.Create(EndDirectory + filename.Substring(filename.LastIndexOf('\\')))) | |
{ | |
SourceStream.CopyTo(DestinationStream); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment