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!

filename as variable

Status
Not open for further replies.

strayrog

MIS
Feb 2, 2005
54
US
All,

I am looking for any help on how I can put a filename into a variable using vb.
Example: filename = 123.abc-xyz.txt I would like to put the following in to variables: v1=123, v2=abc, v3=xyz v4=txt.
Thank you in advance
Strayrog
 



hi,

Example: filename = 123.abc-xyz.txt I would like to put the following in to variables: v1=123, v2=abc, v3=xyz v4=txt.
Code:
filename = V1 & "." & v2 & "-" & v3 & "." & v4  '123.abc-xyz.txt


Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I read it that the OP has the filename, and wants to fill the other four variables with parts of the filename.

If so, the Split function is one option. Split the filename by the "." first, then by the "-".

Code:
filename="123.abc-xyz.txt"

arr1 = split(filename, ".")
v1 = arr1(0)
v4 = arr1(2)

arr2 = split(arr1(1), "-")
v2 = arr2(0)
v3 = arr2(1)

wscript.echo "v1=" & v1 & " v2=" & v2 & " v3=" & v3 & " v4=" & v4
 
Skip, thank you for your reply, but i have the filename already and I need to break it apart into variables.

Guitarzan, thank you for your reply as well. I beleive that is what I was looking for. I will plug that in to my script today.

Thanks again to everyone.
Strayrog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top