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

Script to open file with random characters and extension.

Status
Not open for further replies.

AlexIT

Technical User
Jul 27, 2001
802
US
I have a couple programs generating files into different directories...so I don't always know what extension they will be. Since they save as previous plus one (like log0001.txt, log0002.txt etc.) I had a script that worked in VBA when I knew the extension but now I want to use the users default program to open it, whatever the extension is. Here is what I tried so far. (I know now that the Case won't work this way but I havent changed it to nested if then yet.)

Anyone have a better way to deal with this?


Set fso = CreateObject("Scripting.FileSystemObject")

Part = InputBox("Enter Number without extension:", "Number")
Nm = Left(Part, 1)

If (Nm <> "L") Then
flpath = "//server/released/"
dn = Val(Part)
Select Case dn
Case < 3000
fldir = "1-2999/"
Case < 5000
fldir = "3000-4999/"
Case < 6000
fldir = "5000-5999/"
Case < 7000
fldir = "6000-6999/"
Case < 8000
fldir = "7000-7999/"
Case Else
fldir = "200000-/"
End Select
End If

If Nm = "L" Then
flpath = "//server/ls/"
dn = Val(Right(Part, (Len(Part) - 1)))
Select Case dn
Case < 7000
fldir = "L01000-L06999/"
Case < 8000
fldir = "L07000/"
Case < 9000
fldir = "L08000/"
Case Else
fldir = "L09000/"
End Select
End If
i = 0
Set folder = fso.GetFolder(path & dir)
For Each file In folder.Files
If (Left(file.Name, Len(Part))) = Part Then
ext = Right(file.Name, (Len(file.Name) - Len(Part)))
FileNm(i) = flpath & fldir & Part & ext
i = i + 1
End If
Next

For j = 0 to UBound(i)
Check = fso.FileExists(FileNm(j))
If Check Then
Createobject("wscript.shell").run FileNm(j)
End If
Next j
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top