I have a filename variable that contains : "Filename.csv"
. To extract the filename from a path I use: Filename=Dir([fStr])
where fStr
is retrieved from the file that I selected.
I only need the filename without ".csv"
. How do I remove the ".csv"
extension?
It's best to use a function like GetBaseName()
instead of relying on functions to replace text. Windows allows periods to appear within the base filename so something like this is legitimate:
My .csv for Bob.csv
Using Replace()
would result in:
My for Bob
Not what you're looking for. A better approach would be:
Filename = CreateObject("Scripting.FileSystemObject").GetBaseName(fStr)
You can use the replace function:
Filename = replace(Dir([fStr]),".csv","")
Too late to answer it, might be helpful for future
Try this
Mid(fileName, 1, InStr(1, fileName, ".") - 1)
It will work with any file extension or filename
For example:
fileName : ThisIsMyFile.csv
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With