0

I need to change a lot of filenames, get rid of special characters (ç, for instance - but it is better if it could be tailored for a list of values instead of one at a time). I'm not vbs proficient, but already found some code and tried to make it math my needs, but still it is not working.

This code changes the files in the specified folder "C:\Users\user\Desktop\test", but not the ones in the subfolders after that path.

Set objFso = CreateObject("Scripting.FileSystemObject")
Set Folder = objFso.GetFolder("C:\Users\user\Desktop\test")

For Each Subfolder in Folder.SubFolders
    For Each File In Folder.Files
        sNewFile = File.Name
        sNewFile = Replace(sNewFile,"ç","+")

        if (sNewFile<>File.Name) then 
            File.Move(File.ParentFolder+"\"+sNewFile)
        end if

    Next
Next

Any help, please??

0

1 Answer 1

2

You are not using the Subfolder element in your loop.

An alternative recursive solution is below:

Set objFso = CreateObject("Scripting.FileSystemObject")
Browsefolder objFso.GetFolder("C:\Users\user\Desktop\test")

Sub Browsefolder(Folder)
    For Each Subfolder In Folder.Subfolders
        Browsefolder Subfolder
    Next
    For Each File In Folder.Files
        sNewFile = File.Name
        sNewFile = Replace(sNewFile, "ç", "+")
        If (sNewFile <> File.Name) Then
            File.Move (File.ParentFolder & "\" & sNewFile)
        End If
    Next
End Sub 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .