Windows Scripting

I need a script by the end of today to do the following.

search through folders I specify and then any subfolders listed within that folder
find all Excel files listed if it finds the text that I want replaced it will replace it. Save it and close
the file. so when I go to open the file it will already be changed.
LVL 2
stevenabdulAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KenMcFCommented:
not a script but take a look at replace magic http://www.replacemagic.com/
This will do what you are looking for. It can be done in VBScript but might be a little hard.
0
stevenabdulAuthor Commented:
I have the script to replace the text but I need the part that will search through the folders and subfolders. I dont want to have to pay for the software as it will be a one time deal.
0
Bill PrewIT / Software Engineering ConsultantCommented:
So you will need to specify a list of "root" folders to scan, they aren't all under one parent?

And what file extension(s) do you want it to look for, just XLS, or others as well?

~bp
0
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

stevenabdulAuthor Commented:
yes they are, it will be as an example c:\scripts\accounts\subfolders
0
stevenabdulAuthor Commented:
Just XLS files
0
Bill PrewIT / Software Engineering ConsultantCommented:
Okay, here's some code to process your list of folders to scan, and recursively look or all XLS files in them.  Add your logic to the ProcessFile() subroutine that you have to do the replace text logic.

Option Explicit

Dim objFSO, arrDir, arrExt, strDir

arrDir = Array("c:\scripts\accounts\subfolder1","c:\scripts\accounts\subfolder2","c:\scripts\accounts\subfolder3")
arrExt = Array(".xls")

Set objFSO = CreateObject("Scripting.FileSystemObject")

For Each strDir In arrDir
   ScanFolder objFSO.GetFolder(strDir)
Next

Set objFSO = Nothing


Sub ScanFolder(objFolder)
   Dim objFile, objSubFolder, strExt

   For Each objFile In objFolder.Files
      For Each strExt in arrExt
         If Lcase(Right(objFile.Name, Len(strExt))) = LCase(strExt) Then
            ProcessFile objFile
            Exit For
         End If
      Next
   Next
   For Each objSubFolder in objFolder.SubFolders
      ScanFolder objSubFolder
   Next
End Sub

Sub ProcessFile(objMyFile)
   Wscript.Echo "File: " & objMyFile.Path
End Sub

Open in new window

~bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stevenabdulAuthor Commented:
Billprew I will try this tomorrow and let you know how it turns out. Thanks
0
huacatCommented:
I'd like using a command(run them under command prompt, please change the folder first) to do it:
for /r %l in (*.xls) do Replace "%l"

Open in new window


and Replace is your script which to replace something.
0
stevenabdulAuthor Commented:
the script didnt work how I wanted, but these guys put forth the effort.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.