| |
Rowena
Posts: 1
Score: 0
Joined: 7/15/2004
From:
Status: offline
|
Hi, I want to search a folder and its sub folders for a certain file name, change the file name and write out its full path to text file. I thought I had completed teh script, but it only reached some of the files, perhaps 50 out of 100. I can't see a pattern to which ones weren't reached by the search. Any suggestions would be appreciated. Thanks [code] '=========================================================== ' Searches the current folder and sub folders ' for soil.dbf files, renames them with a number ' and writes out the directory to soil.txt '============================================================ option explicit '==================== ' Run the function '==================== call IndexScripts Dim count 'variable for number of soil tables sub IndexScripts() count = 0 dim fso, loc, log set fso = createobject("scripting.filesystemobject") if WScript.Arguments.Count = 0 then loc = fso.GetAbsolutePathName(".") else loc = WScript.Arguments(0) end if '=================================== ' open output file to store results '=================================== Set log = fso.CreateTextFile("soil.txt", true) GetWorkingFolder loc, 0, 1, log set fso = nothing MsgBox "Process complete. " & cstr(count) & " SOIL.dbf files found." End Sub '================================================== 'called recursively to get a folder to search '================================================== function GetWorkingFolder(foldspec, foldcount, firsttime, log) dim fso, fold, foldcol, name, remaincount, sf Set fso = CreateObject("Scripting.FileSystemObject") set fold = fso.GetFolder(foldspec) set foldcol = fold.SubFolders if firsttime = 1 then If fold.name = "SOIL.dbf" then count = count + 1 name = "SOIL" + cstr(count) + ".dbf" f.name = name log.WriteLine sf.path log.WriteLine fold.path End If foldcount = foldcol.count firsttime = 0 end if remaincount = foldcol.count '===================================================== ' Loop through each subfolder in folder collection '===================================================== for each sf in foldcol If sf.name = "SOIL.dbf" then count = count + 1 name = "SOIL" + cstr(count) + ".dbf" f.name = name log.WriteLine sf.path End if '================================================= ' Loop through each file in file collection '================================================= Dim fc, f Set fc = sf.files For Each f In fc If f.name = "SOIL.dbf" then count = count + 1 name = "SOIL" + cstr(count) + ".dbf" f.name = name log.WriteLine f.path End IF Next remaincount = GetWorkingFolder (foldspec +"\"+sf.name, remaincount, firsttime, log) next set fso = nothing GetWorkingFolder = foldcount - 1 end function [code]
|
|