2016-03-22 21 views
0

ディレクトリの名前を変更しようとしていますが、すでに存在する場合は番号を増やすだけです。ディレクトリの名前を増やしながら名前を変更する場合


Folderは、今そこにFolderであり、再度アプリケーションを実行Folder1
が今ようにFolderFolder2に改名作ってしまう滞在することができますFolder1
に変更されます。

現在のコード

If Directory.Exists(path2) Then 
      Try 
       My.Computer.FileSystem.RenameDirectory(path2, "Application Data.old") 
      Catch 
       Exit Sub 
      End Try 
End If 

みんなありがとう!

答えて

0

これは擬似コードです。実際のコードに変換する必要があります。ここであなたはそれを行う方法

Imports System.IO 
Imports System.Linq 

Dim newFolderName As String 
Dim dirs() As String Directory.GetDirectories("<base dit path>") 'BTW - Directory is real object name 
If dirs.Length > 0 Then 
    Dim maxDir As Integer = dirs.Select(
     Function(d) 
      Dim dirNO As Integer 
      If d.StartsWith("Folder") AndAlso d.Length > 6 AndAlso 
       Integer.TryParse(d.Substring(6), dirNO)) Then 
       Return dirNO 
      Else 
       Return 0 
      End If 
     End Function).Max() 
    newFolderName = "Folder" & (maxDir + 1) 
    If Directory.Exists("<base dit path>\Folder") Then 
     Directory.Rename("<base dit path>\Folder", newFolderName) 
    End if 
Else 
    Directory.Create("Folder") 
End If 
+0

それは私が必要とするもののように見えます。私はその日に出発しましたが、私は朝にそれを試み、結果を投稿します。当時はありがとうございました! – dwb

+0

@dwbあなたは少しそれを実際のコードに微調整する必要がありますが、それはカバーする必要があります。問題が発生した場合はお知らせください –

関連する問題