• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

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.
0
stevenabdul
Asked:
stevenabdul
2 Solutions
 
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 PrewCommented:
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
stevenabdulAuthor Commented:
yes they are, it will be as an example c:\scripts\accounts\subfolders
0
 
stevenabdulAuthor Commented:
Just XLS files
0
 
Bill PrewCommented:
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now