vb right function

I am referencing the following file. But i need to make it more dynamic.
The file name will change each time except for the last 6 characters of the file FREDDY. But I will also need to exclude the .dat section.

If I do something like

Dim Process_Claims_File – righttrim

load_success=Process_Claims_File ("\\server\Renewal_Date_Capture\RDCDATA000001FREDDY.dat", myClaims_Journal)
aneilgAsked:
Who is Participating?
 
Alan_WhiteCommented:
Have a play around with this function I've knocked up, it might be close to what you are after.
wscript.echo getDatFileName("\\server\Renewal_Date_Capture")

Function getDatFileName(sFolder)
	
	getDatFileName = "Not Found"

	Dim oFSO, oFolder, oFile
	Set oFSO = CreateObject("Scripting.FileSystemObject")

	If oFSO.FolderExists(sFolder) Then
		Set oFolder = oFSO.GetFolder(sFolder)
		For Each oFile In oFolder.Files
			If LCase(Right(oFile.Name,4)) = ".dat" Then
				getDatFileName = oFile.Name
			End If
		Next
	End If	

End Function

Open in new window

0
 
Patrick MatthewsCommented:
aneilg,

Please elaborate on what you are trying to do.

Patrick
0
 
Bill PrewCommented:
Not sure what your question is?

Are you trying to figure out how to locate the "new" file, based on looking for just FREDDY?

Or are you asking how to extract the FREDDY from the file name that will change each day?

~bp
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
can you please clarify the issue?
do you need the 00001 part "set" into the string, or extracted from the string?
aka where does which value come from?

if you want to "set" the value, you might do something like this:

dim strFile 
strFile = "\\server\Renewal_Date_Capture\RDCDATA$$$$$$FREDDY.dat"
strFile = replace(strFile, "$$$$$$", right( "000000" & your_number , 6 )) 
load_success=Process_Claims_File (strFile, myClaims_Journal) 

Open in new window


hope this helps
0
 
Alan_WhiteCommented:
Sorry, I dont really understand the question, can you try again?

In general, the Right function will return the rightmost characters of a string.  eg wscript.echo  Right("ThisIsAnExample",3)  will produce "ple"

The Left function will do similar on the leftmost characters.  eg wscript.echo  Left("ThisIsAnExample",3) will produce "Thi"

Perhaps you want the leftmost characters excluding the rightmost 6 (for FREDDY) and 4 (for .dat)?

If so, Left(strYourVarilable,Len(strYourVariable)-10) should produce that.

Still not sure what you are going to do with that though?
0
 
aneilgAuthor Commented:
hello sorry.
i just need to Identify the file name from freddy.
the location will always be the same.

so if the file is ("\\server\Renewal_Date_Capture\RDCDATA000001FREDDY.dat", myClaims_Journal)
i know i nedd to process file freddy.

or if the file is ("\\server\Renewal_Date_Capture\RDCDATA000001abcdef.dat", myClaims_Journal)
i know i nedd to process file abcdef.
0
 
Bill PrewCommented:
How about this:

strFile = "\\server\Renewal_Date_Capture\RDCDATA000001abcdef.dat"
strPiece = Right(Left(strFile, Len(strFile)-4), 6)

Open in new window

~bp
0
 
aneilgAuthor Commented:
thanks.
0
 
aneilgAuthor Commented:
sorry guys my mistake.

basically what i want to do is read a file from a path.
 ("\\server\Renewal_Date_Capture\RDCDATA000001FREDDY.dat", myClaims_Journal)

i want to take out RDCDATA000001FREDDY.dat and use that file name.
0
 
Alan_WhiteCommented:
So, are you saying that there is a file in a folder that you want to use and that it has a name that you don't know but it will end in FREDDY.dat?
0
 
aneilgAuthor Commented:
Sorry for the confusion guys.

What I want to do is just get the .dat file name, irrespective of what the file is called.
I want to get the name of the .dat file from the folder.
0
 
aneilgAuthor Commented:
on my folder, the faile name can be anything.
("\\server\Renewal_Date_Capture\RDCDATA000001FREDDY.dat", myClaims_Journal)

or
("\\server\Renewal_Date_Capture\RDCDATA000001PAUL.dat", myClaims_Journal)

i need to get the .dat file name.
0
 
Alan_WhiteCommented:
Okay, we are getting somewhere.

Is the path and partial filename always the same?

Path is always \\server\Renewal_Date_Capture?
File name always starts with RDCDATA000001?
File name always ends with .dat?

Will there be many files in this folder when the script runs or just one?
0
 
aneilgAuthor Commented:
thanks for your help alan.

the folder will always be the same.
the file will NOT start with RDCDATA000001.
the file will always end in .dat.

so i need the name of the full .dat file to use.
0
 
Alan_WhiteCommented:
And there will only be one .dat file in the folder when you run the script?
0
 
aneilgAuthor Commented:
thanks alan.

really do Appreciate your help.
0
 
aneilgAuthor Commented:
fandabidozi
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.