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!

How to acces file with random string? 1

Status
Not open for further replies.

vin200

Technical User
Apr 14, 2010
7
CA
I need to access a text file which is contained in a folder whose name is a random set of 6 digits. I need to run a script on multiple computers and therefore the 6 digits will be different on each, but the text file will be the same.

I can't use wildcards, so how do i do this?

Thanks.
 


Hi,

What code do you have so far?

What is the business case for this requirement?

Sounds like a homework problem to me.

Please answer all questions.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
dim StrFileName, StrContents, strLineCount


Set objNetwork = wscript.CreateObject("wscript.network")



StrFileName = "C:......\Users\xxxxxx\myfile.txt"

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objTS = objFS.OpenTextFile(StrFileName, 1)


strContents = objTS.ReadAll
objTS.close


StrContents = Split(StrContents, vbNewLine)

strLineCount = UBound(StrContents)


Set objTS = objFS.OpenTextFile(strFileName, 2)
i=0
do while i<12
objTS.WriteLine (strContents(i))
i = i+1
loop


objTS.WriteLine ("update_here", true);")


i = i+1
do while i<= strLineCount
objTS.WriteLine (strContents(i))
i = i+1
loop


I work at a college, and need to update a text file on all of the college computers. Not a homework question lol.

 
So that xxxxxx file is a different string each time. I need a way of accessing the myfile.txt.

thanks
 


Isn't that a SUBFOLDER of C:......\Users???

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Sorry, to make another post. But I'm guessing the reason you thought it was a HW question was because i said "I can't use wildcards". The reason i wrote that was because, to my knowledge there are no wildcards in vbs, correct?
 


There's your answer. No wildcards required.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Wait, I don't understand. Even if it is a subfolder how does that make a difference? I still need to go through the subfolder to get to the text file, no?

Sorry if I sound like a n00b...
 



Yes, you loop thru THAT folder.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 



Hmmmmm. ALL the computers? Why would that information not be on a network drive?

Oh well!
Code:
    Dim oFSO, oFolder, oSub, oFile
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set oFolder = oFSO.GetFolder("C:\SomePath")
    
    For Each oSub In oFolder
        For Each oFile In oSub.Files
            
        Next
    Next

    Set oSub = Nothing
    Set oFolder = Nothing
    Set oFSO = Nothing


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hi, thanks for the help. Should I be setting oSub as well? I get an object doesn't support this property at the first for loop
 



sorry...
Code:
    For Each oSub In oFolder.subfolders

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top