0

I have a folder that contains many other folders with csv files within them that I need to rename

I currently have this that does not work

Set Fso = CreateObject("Scripting.FileSystemObject")
ShowSubfolders FSO.GetFolder("C:\Temp\AMLReports\")

Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
    Wscript.Echo Subfolder.Path
    ShowSubFolders Subfolder
    sNewFile = File.Name
    sNewFile = Replace(sNewFile,"OLDNAMEPART","NEWNAMEPART")
    if (sNewFile<>File.Name) then 
        File.Move(File.ParentFolder+"\"+sNewFile)
    end if

Next
End Sub

This script works for single level :

Set objFso = CreateObject("Scripting.FileSystemObject") 
Set Folder = objFSO.GetFolder("C:\Temp\AMLReports\") 
For Each File In Folder.Files 
    sNewFile = File.Name 
    sNewFile = Replace(sNewFile,"oldpartname","new part name") 
    if (sNewFile<>File.Name) then 
        File.Move(File.ParentFolder+"\"+sNewFile) 
    end if
Flakes
  • 2,414
  • 8
  • 27
  • 30
MilesIt
  • 9
  • 1
  • 1
    First get the recursion working and tested then add the other logic. See the duplicate for the correct recursive pattern that is tried and tested. – user692942 Jun 09 '21 at 04:34

0 Answers0