such a silly question I know, but I want to remove the filename in a string such as
"blah\bleurgh\filename.txt"
To delete the extension I would do
strFile = Left(strFile, InStrRev(开发者_StackOverflowstrFile, ".") - 1)
But doing similiar to delete the filename at the end does nothing, e.g.
tempStrFile = Left(tempStrFile, InStrRev(tempStrFile, "\") - 1)
A "\\" doesn't work either, incase it was an escape character issue.
Many thanks!
edit: for further information what I want to do is if given a filename such as "filename.txt" I want to output "output_filename.csv" - I have no problems with this.
If I get a directory though such as "blah\filename.txt" I have difficulty sticking output in the middle to get "blah\output_filename.csv"
If I understand what you want, then your code works for me, the following code:
dim tempStrFile
tempStrFile = "blah\bleurgh\filename.txt"
tempStrFile = Left(tempStrFile, InStrRev(tempStrFile, "\") - 1)
tempStrFile = tempStrFile & "\output_filename.csv"
msgbox tempStrFile
will output blah\bleurgh\output_filename.csv
which I belive is what you want.
精彩评论