Parent page: Service Functions – System (QTP, VBScript)
Use FileSystemObject.GetFile method to obtain a File object.
Argument should be a full path string.
Set FSO = CreateObject(“Scripting.FileSystemObject”)
Check if the file exists first.
When to use it? There is a variety of utility tasks related to it: get parent folder, create another file in the same folder, create another file with the same name, etc.
Does file format matter? No. It could be text file, excel spreadsheet, bitmap, binary file, – anything. Just make sure you pass into both filename and extension.
Note. Always release the object you created when you no longer need it. If you don’t do that in the long run it’ll cause you memory leakage problem.
sFileName = "C:\TEMP\Log145473.txt" Set objFile = FSO.GetFile(sFileName) sName = objFile.Name sPath = objFile.Path sPath = Left(sPath, Len(sPath)-Len(sName)) Set objFile = Nothing Set FSO = Nothing 'sName contains "Log145473.txt" 'sPath contains "C:\TEMP\"