Having fun with computer, gadget, programming, electrical, electronic, robotic, and technology. Get file extension in VBScript. A reader asked a question about my previous post on replacing underscore...
Having fun with computer, gadget, programming, electrical, electronic, robotic, and technology. Get file extension in VBScript. A reader asked a question about my previous post on replacing underscores in filenames with spaces. I decided to answer the question here. The question was how to check if a file exists with wildcards within a timeframe using VBScript.
To get the file extension in VBScript, search for the last dot with InStrRev. Use that dot position to get where the extension starts. A VBS file contains VBScript code to run in Windows and perform functions.
When running a script from command line versus the monitor, the file type value differed for log files. The type value was “LOG File” from command line but “Text Document” from the monitor. So no log files were found since the types did not match. The file type property should be consistent but is not. Should this bug be reported?
Another way is to step backwards through the file path passed in, looking first for a backslash, then a dot. Use those character positions to extract the filename.
If Windows recognizes the file extension as a specific type, this function returns that lower case type name, like “video” for AVI and MP4 files. The type comes from the Registry. If no perceived type exists, it returns an empty string.