Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBS Wild Cards

Status
Not open for further replies.

tab1962

IS-IT--Management
Sep 15, 2009
3
US
Ithere a wildcard that I can put in this vbs file that would search all the directories and remove any comma's? So far it works fine with one folder at a time. Here is my VBS file text-

Const folder = "C:\Documents and Settings\tomabaker\My Documents\Scans\ID*.*\"

With CreateObject("Scripting.FileSystemObject")
On Error Resume Next
For Each file In .GetFolder(folder).Files
file.Name = Replace(file.Name, ",", "")
Next 'file
End With 'FSO
 
use .SubFolders to return a list. Then iterate them like you do with the files.

CONST strFolder = "C:\Documents and Settings\tomabaker\My Documents\"

With CreateObject("Scripting.FileSystemObject")
For Each objFolder In .GetFolder(strFolder).SubFolders
For Each objFile In objFolder.Files
objFile.Name = Replace(objFile.Name, ",", "")
Next 'file
End With
End With 'FSO

-Geates
 
Wow, I just lost points for not observing that.

CONST strFolder = "C:\temp\"

set objFSO = CreateObject("Scripting.FileSystemObject")

function traverseDir(strDir)
set objFolder = objFSO.GetFolder(strDir)

for each objSubFolder in objFolder.SubFolders
traverseDir(objSubFolder.Path)
next

for each objFile in objFolder.Files
if (instr(objFile.Name, ",")) then objFile.Name = replace(objFile.Name, ",", "")
next
end function

traversDir(strFolder)

-Geates
 
I tried this but getting a runtime error on type Mismatch 'traversDir' any ideas?

Here is my edited file
CONST strFolder = "C:\Documents and Settings\tomabaker\My Documents\Scans"

set objFSO = CreateObject("Scripting.FileSystemObject")

function traverseDir(strDir)
set objFolder = objFSO.GetFolder(strDir)

for each objSubFolder in objFolder.SubFolders
traverseDir(objSubFolder.Path)
next

for each objFile in objFolder.Files
if (instr(objFile.Name, ",")) then objFile.Name = replace(objFile.Name, ",", "")
next
end function

traversDir(strFolder)
 
Sure, the function name is traverseDir, not traversDir. Just a typo

-Geates
 
It worked! Now I can remove the other special characters! You guys are awesome thanks.

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top