-
March 13th, 2014, 10:20 PM
#1
Parsing a Filename Help
Hello everyone, I am new to the forums. I hope that someone can help me. I am new to VBS also and need to automate a script that I found online. I need the file name to be parsed a bit and I am not sure how to do it.
In the code below I am putting the filename plus "BB" into a txt file but I want to format the output of file.Name. For example, a file name is HHC_TTT_Doe_JOE_2013023.pdf and I just want want "HHC" or "TTT" or "JOE" or "2013023", how exactly do I do it? The lengths of the characters in the file name varies but it is separated by an underscore (_)
file.Name & " bb"
Code:
Function ProcessScript
Dim folderSpec, file
GetUserInput folderSpec, "Please enter the unc path to the source folder", scriptBaseName, "C:\help"
If objFSO.FolderExists(folderSpec) Then
For Each file In objFSO.GetFolder(folderSpec).Files
LogToFile scriptPath & "\" & scriptBaseName & ".txt", file.Name & " bb"
Next
End If
End Function
I just want a way to output the filename based on the underscores. I know there is something like this:
Code:
File = Split(File.Name,"-")
secondvalue = File(1)
firstvalue = File(2)
I want to be able to do something like this
Code:
LogToFile scriptPath & "\" & scriptBaseName & ".txt", file.Name & " bb" & firstvalue & secondvalue
-
March 13th, 2014, 10:33 PM
#2
Re: Parsing a Filename Help
Yes you can use Split() of course in your sample you are using a dash rather than an underscore so that would not work
If you just want to removed the underscores you can use the Replace() method to replace them with an empty string as well.
Always use [code][/code] tags when posting code.
-
March 13th, 2014, 10:37 PM
#3
Re: Parsing a Filename Help
I tried using :
Code:
File = Split(File.Name,"_")
secondvalue = File(1)
firstvalue = File(2)
In my for each loop and it doesn't recognize File.Name, I am sure I am doing this incorrectly.
-
March 14th, 2014, 12:28 AM
#4
Re: Parsing a Filename Help
You are trying to use file for 2 different things in the same section of code. You can't do that
Since File is the object you are using for your for each loop you need another var to hold the string you are splitting from it.
I assume that the file object there would have a .Name property but honestly I do not write VB Script and this really is not the correct place for scripting questions.
Also note that you should not use the word File as a variable name
Always use [code][/code] tags when posting code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|