0

I am trying to copy files from a folder and paste them in another created folder

I already created the folder with the code below:

DirectoryInfo di = Directory.CreateDirectory(path); 

where path is the path of where the folder is created.

How can I fill this folder with files from another folder pls.

Thanks

2 Answers 2

1

This should give you what you need:

http://msdn.microsoft.com/en-us/library/cc148994.aspx

Sign up to request clarification or add additional context in comments.

Comments

0

This will find and copy files with the specified search param.

public static void findAndCopy(string _sourcePath, string _destPath, string _searchParam ) { if (System.IO.Directory.Exists(_sourcePath)) { string[] files = System.IO.Directory.GetFiles(_sourcePath, _searchParam, System.IO.SearchOption.AllDirectories); string destFile = ""; string fileName = ""; // Copy the files foreach (string s in files) { // Use static Path methods to extract only the file name from the path. fileName = System.IO.Path.GetFileName(s); destFile = System.IO.Path.Combine(_destPath, fileName); try { System.IO.File.Copy(s, destFile, false); } catch (UnauthorizedAccessException uae) { log.Warn(uae); } catch (IOException ioe) { log.Warn(ioe); } } } else { log.Error("Source path not found! " + _sourcePath); } }//end findAndCopy 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.