12/22/2023 0 Comments Directory List & Print 4.27 instalString sourceDirectory = destinationDirectory = destinationDirectory) The original directory no longer exists after it has been moved. The following example demonstrates how to move a directory and all its files to a new directory. String archiveDirectory = files = from retrievedFile in Directory.EnumerateFiles(archiveDirectory, "*.txt", SearchOption.AllDirectories)įrom line in File.ReadLines(retrievedFile)Ĭonsole.WriteLine(" lines found.", ()) The following example demonstrates how to use the EnumerateFiles method to retrieve a collection of text files from a directory, and then use that collection in a query to find all the lines that contain "Example". Let fileName = currentFile.Substring(sourceDirectory.Length + 1)ĭirectory.Move(currentFile, Path.Combine(archiveDirectory, fileName))ĭim sourceDirectory As String = "C:\current"ĭim archiveDirectory As String = "C:\archive"ĭim txtFiles = Directory.EnumerateFiles(sourceDirectory, "*.txt")įor Each currentFile As String In txtFilesĭim fileName = currentFile.Substring(sourceDirectory.Length + 1) Let sourceDirectory = archiveDirectory = txtFiles = Directory.EnumerateFiles(sourceDirectory, "*.txt") String fileName = currentFile.Substring(sourceDirectory.Length + 1) ĭirectory.Move(currentFile, Path.Combine(archiveDirectory, fileName)) String sourceDirectory = archiveDirectory = txtFiles = Directory.EnumerateFiles(sourceDirectory, "*.txt") After the files are moved, they no longer exist in the original directory. The following example shows how to retrieve all the text files from a directory and move them to a new directory.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |