0

Found a nice piece of vbScript code on SuperUser that can function like find and replace in Office to locate and change characters/words in a folder to mass edit them to your liking. I was wondering if this code could be expanded upon to call any and all sub folders under the root target folder?

Set objFso = CreateObject("Scripting.FileSystemObject")
Set Folder = objFSO.GetFolder("c:\test\")

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

https://superuser.com/questions/197380/how-do-i-find-and-replace-a-character-in-filenames-in-windows-7-using-explorer

Community
  • 1
  • 1
  • Yes you can, you can create a recursive function to navigate to all subfolders and from that call your `For Each` loop to change the files. – Victor Moraes Oct 12 '16 at 18:22
  • How exactly would you do that? Sorry not a coder but very much appreciate the help your giving. – user7009566 Oct 12 '16 at 18:28
  • You can research on the already asked questions, [like this one](http://stackoverflow.com/a/14965606/6352151) – Victor Moraes Oct 12 '16 at 18:31
  • to give you an example how easy this is in Ruby in one line: `Dir['*/**/*'].each {|f| File.rename(f, File.join(File.dirname(f),File.basename(f.gsub('_', ''))))}` – peter Oct 12 '16 at 21:59

0 Answers0