Some clarification as to descriptions I use:
- FullName = Path + FileName (Includes Drive + FileExt if present) (e.g. C:\path\filename.ext)
- Path = Folder path only (Including Drive). Should not include FileName. May or may not end with a PathSeparator (e.g. C:\path\ or C:\path )
- FileName = Name of file (Includes FileExt if present). Should not include Path (e.g. filename.ext)
Lately I've been pondering extracting information from file & folder names.
We already know how to do this!
Are you certain about that?
Here's a test - how do you write a function to return the file path from a FullName string?
I am guessing that most would answer something like this:
![]()
Please Login or Register to view this content.
But what if someone passes a Path instead of a FullName argument?
Our function could fail. (e.g. "C:\path1\path2" would return as "C:\path1\" - we would lose part of the folder path without realising)
So I've felt the need to rethink the basics of any procedures that deal with file/folder names.
I want the functions to avoid returning incorrect results - as far as possible - regardless of whether the input is a fullname / filepath / filename
(e.g. a function for returning folder path should return an empty string where the input was a filename)
At this point, someone will say "why don't you validate the file/folder existence with Dir or FSO"?
But that won't work if you are dealing with a worksheet range listing files and/or folders from another PC.
So after some tinkering, below is as far as I can reach. If anyone can think of a way to tighten these functions, I'd be interested!
![]()
Please Login or Register to view this content.
UPDATE:
I could alter the fnstrGetPathFromFullName procedure so that it checks for a file extension seperator - similar to what I did in fnstrGetFileNameFromFullName
But it would still fail on filenames that lack extensions
Bookmarks