For example, you could highlight a word, a line, a paragraph, or all the text in the document. How to copy and paste text on a desktop or laptop computer Copying text Copy and paste text on an Apple iPhone and iPad.Copy and paste text on an Android smartphone and tablet.Copy and paste from a Linux shell to the X11 clipboard.Copy and paste in a Windows command line.How to copy and paste text in a document.Copy and paste text on a desktop or laptop computer.The code below is microsoft suggestion how-to-copy-directoriesĪnd it is shared by dear it just copies sub directories and files of source folder recursively and doesn't copy the source folder it self (like right click -> copy ).īut there is a tricky way below this answer : private static void Director圜opy(string sourceDirName, string destDirName, bool copySubDirs = true)ĭirector圜opy(subdir. String temppath = Path.Combine(destDirName, subdir.Name) ĭirector圜opy(subdir.FullName, temppath, copySubDirs) If copying subdirectories, copy them and their contents to new location. String temppath = Path.Combine(destDirName, file.Name) Get the files in the directory and copy them to the new location. If the destination directory doesn't exist, create it. "Source directory does not exist or could not be found: "ĭirectoryInfo dirs = dir.GetDirectories() Get the subdirectories for the specified directory.ĭirectoryInfo dir = new DirectoryInfo(sourceDirName) Private static void Director圜opy(string sourceDirName, string destDirName, bool copySubDirs) Copy from the current directory, include subdirectories. You can always use this, taken from Microsofts website. SourceFile.CopyTo(Path.Combine(target.FullName, sourceFile.Name), overwiteFiles)) Parallel.ForEach(source.GetFiles(), sourceFile => Parallel.ForEach(source.GetDirectories(), (sourceChildDirectory) =>ĬopyEntireDirectory(sourceChildDirectory, new DirectoryInfo(Path.Combine(target.FullName, sourceChildDirectory.Name)))) public static void CopyEntireDirectory(DirectoryInfo source, DirectoryInfo target, bool overwiteFiles = true) String output = Regex.Replace(fileName, "^" + Regex.Escape(path), newPath) ĭirectory.CreateDirectory(Path.GetDirectoryName(output)) ĮDIT: Modifying Sabry to full parallel foreach does produce a better result, however the code uses recursive function and its not ideal in some situation. Parallel.ForEach(Directory.GetFileSystemEntries(path, "*", SearchOption.AllDirectories) public static void CopyEntireDirectory(string path, string newPath) My solution is basically a modification of answer, however I have enhanced it a bit and it appears to be more than 5 times faster than the accepted answer. String multiDest = StringArrayToMultiString(dest) įileOpStruct.pTo = Marshal.StringToHGlobalUni(multiDest) įileOpStruct.fFlags = (ushort)_NOCONFIRMATION String multiSource = StringArrayToMultiString(source) Win32.SHFILEOPSTRUCT FileOpStruct = new Win32.SHFILEOPSTRUCT() įileOpStruct.wFunc = (uint)Win32.FO_MOVE Public static bool Move(String source, String dest) Int retval = Win32.SHFileOperation(ref FileOpStruct) What's wrong with the following straightforward method? public static void CopyFilesRecursively(DirectoryInfo source, DirectoryInfo target) ) įileOpStruct.pFrom = Marshal.StringToHGlobalUni(multiSource) įileOpStruct.fFlags = (ushort)_SILENT | (ushort)_NOCONFIRMATION | (ushort)_NOERRORUI | (ushort)_NOCONFIRMMKDIR įileOpStruct.hNameMappings = IntPtr.Zero Hmm, I think I misunderstand the question but I'm going to risk it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |