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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to list all txt file in a file, present in subdirectory 1

Status
Not open for further replies.

hep1058

Technical User
Feb 23, 2004
5
CA
Hi,
I found some exemple enabling me to paste the file name and location in a text file, which are present in a giving directory. But I can only do so by defining a specific drive. i.e : strFolder = "C:\tets\"
It doesnt perform a search on a subdirectory.

But I would like to be able to specify "c:\test\" as the starting point and the script would be able to see that a subDirectory name... \"Test2" exist and perform the search ALSO in this subdir.

Actual structure C:\Test\test2\*.txt

*Find all .txt file with name by providing "c:\test\"

I am not very good but here's what I got for the moment.

strFolder = "C:\TEST\"
set fsoObj = CreateObject("Scripting.FileSystemObject")
set objFolder = fsoObj.getfolder(strFolder)
Set oFSO = createobject("scripting.filesystemobject")
Set oNTF = oFSo_Opentextfile("F:\RESULTsearch.txt",8,True)


Call getInfo(objFolder)

Sub getInfo(pCurrentDir)

For Each aItem In pCurrentDir.Files
If LCase(Right(Cstr(aItem.Name), 3)) = "rpt" Then
oNTF.writeline(aItem.Name & " " & objFolder.Path)
End If
Next


For Each aItem In pCurrentDir.SubFolders
getInfo(aItem)
Next


End Sub
wscript.Echo "END"


Thanks a lot.

 
Instead of:
If LCase(Right(Cstr(aItem.Name), 3)) = "rpt" Then
try this:
If LCase(Right(Cstr(aItem.Name), 4)) = ".txt" Then

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thx, It now founds .txt file.
But only for the current Directory "C:\test\"

My disk is as follow:
---------------------
C:\test\info.txt
C:\test\argo.txt
C:\test\treta.txt
C:\test\test2\virtua.txt
C:\test\test2\concerto.txt
C:\test\test2\vip.txt
C:\test\test2\guargantua.txt
and many mores different files...


The script found all the .txt files in "C:\test\" but non in "C:\test\test2\", I need those too. Any Idea ?
 
Replace this:
For Each aItem In pCurrentDir.SubFolders
getInfo(aItem)
Next
by this:
For Each aItem In pCurrentDir.SubFolders
Call getInfo(aItem)
Next
or this:
For Each aItem In pCurrentDir.SubFolders
getInfo aItem
Next


Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Another change.
Replace this:
oNTF.writeline(aItem.Name & " " & objFolder.Path)
by this:
oNTF.writeline(aItem.Name & " " & pCurrentDir.Path)

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top