Чтобы создать папку по имени файла и скопировать файл в VB.NET, вы можете использовать несколько методов. Вот несколько подходов, которые вы можете рассмотреть:
-
Метод 1: использование пространства имен
System.IO:Dim sourceFile As String = "C:\path\to\file.txt" Dim destinationFolder As String = "C:\path\to\destination\folder" ' Extract the filename from the source file path Dim fileName As String = Path.GetFileName(sourceFile) ' Create the destination folder Directory.CreateDirectory(destinationFolder) ' Copy the file to the destination folder File.Copy(sourceFile, Path.Combine(destinationFolder, fileName)) -
Метод 2. Использование класса
My.Computer.FileSystem:Dim sourceFile As String = "C:\path\to\file.txt" Dim destinationFolder As String = "C:\path\to\destination\folder" ' Extract the filename from the source file path Dim fileName As String = Path.GetFileName(sourceFile) ' Create the destination folder My.Computer.FileSystem.CreateDirectory(destinationFolder) ' Copy the file to the destination folder My.Computer.FileSystem.CopyFile(sourceFile, Path.Combine(destinationFolder, fileName))
Эти методы создают папку на основе желаемого пути к целевой папке, а затем копируют файл в эту папку, сохраняя его исходное имя.