I have a list of UNC paths where I want to parse out only the name of the file and I'm having some difficulty. For example, using any of the scenarios below I want to extract "FILENAME.XLS" from the string. The file name and extension will vary in addition to the name and lengths of the folder paths.
varName = "\\server_name\share_name\folder1_name\FILENAME.XLS"
varName = "\\server_name\share_name\folder1_name\folder2_name\FILENAME.XLS"
varName = "\\server_name\share_name\folder1_name\folder2_name\folder3_name\FILENAME.XLS"
I used InStrRev to determine the position of the last \, Len to get the length of the string and subtracted the second from the first to get the file length.
I assume that's what I needed to do, but how do I go about the next step and return the file name as a string to var4?
varName = "\\server_name\share_name\folder1_name\FILENAME.XLS"
varName = "\\server_name\share_name\folder1_name\folder2_name\FILENAME.XLS"
varName = "\\server_name\share_name\folder1_name\folder2_name\folder3_name\FILENAME.XLS"
I used InStrRev to determine the position of the last \, Len to get the length of the string and subtracted the second from the first to get the file length.
Code:
var1 = Len(varName)
var2 = InStrRev(varName, "\")
var3 = (var1 - var2)