2016-10-29 4 views
0

このコードはネットのどこかから取得しています。しかし、私の経験では、メインフォルダ( "C:\ Folder \")のすべてのサブフォルダで実行するには十分ではありません。私はどんな提案も感謝します。すべてのサブフォルダでコードを実行

Sub check() 
Dim strFolder As String 
Dim strFile As String 

    strFolder = "C:\Folder\" 
    strFile = Dir(strFolder & "*.*") 
    Do While Len(strFile) > 0 
    If InStr(strFile, "xxx") > 0 Then 
     Name strFolder & strFile As strFolder & Replace(strFile, "xxx", "yyy") 
    End If 
    strFile = Dir() 
    Loop 
End Sub 
+0

「このコードはネットのどこかから取得しました」 - 悪意のある場合はどうなりますか? –

+0

この行はどうしますか? 'strFolder&strFile strFolderとして&置換(strFile、" xxx "、" yyy ")'?それは有効なVB.NET構文のようには見えません。 –

答えて

0

あなたは、System.IO名前空間を使用してオフにはるかに優れている内AllDirectoriesを検索するオプションを可能Directories.GetFilesの方法があるとして、(あなたはそれのためにImportsステートメントを追加する必要があります)あなたの指定したフォルダ

輸入System.IO;

Sub Check() 
Dim strFolder As String = "C:\Folder\" 
Dim strFiles() As String = Directory.GetFiles(strFolder, "*.*", SearchOption.AllDirectories) 

    For Each strFile As String In strFiles 
     If strFile.Contains("xxx") Then 
      File.Move(strFolder & strFile, strFolder & strFile.Replace("xxx", "yyy")) 
     End If 
    Next 
End Sub 
関連する問題