下面的代碼根據不同的文件名創建多個文件夾,並將這些文件移動到新的文件夾中。例如,文件ABC和XYZ被移動到一個新創建的名爲ABC和XYZ的文件夾中。我想推進代碼以允許稍微不同的文件名進入一個公共文件夾。例如,我想將文件ABC_rock,ABC_soil和ABC_water放入名爲ABC的文件夾中,並將AND文件XYZ_rock,XYZ_soil和XYZ_water放入名爲XYZ的文件夾中。我不想爲ABC_rock,ABC_soil和ABC_water創建單獨的文件夾。任何建議,非常感謝。感謝您的幫助。VB.NET根據文件名創建文件夾
Dim strOutputLocation As String = "C:\Temp"
Dim rootPath As String = strOutputLocation
For Each filepath As String In IO.Directory.GetFiles(rootPath)
Dim folderName As String = IO.Path.GetFileNameWithoutExtension(filepath)
Dim folderPath As String = IO.Path.Combine(rootPath, folderName)
If Not IO.Directory.Exists(folderPath) Then
IO.Directory.CreateDirectory(folderPath)
End If
Dim fileName2 As String = IO.Path.GetFileName(filepath)
Dim newFilePath As String = IO.Path.Combine(folderPath, fileName2)
File.Move(filepath, newFilePath)
Next
完美謝謝! – artwork21 2011-05-04 18:41:45
我試圖通過兩個下劃線__而不是一個來分割,但它只是由第一個_實例分割。我如何通過__分割? – artwork21 2011-05-09 12:37:01