Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


File search

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,1149
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> File search
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 File search - 7/15/2004 10:27:56 AM   
  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]
 
 
Post #: 1
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> File search Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts