I would like to pass the full path of a text file to one of the function. i am placing the my script, and text file at same location by using the below command i found the folder path where my script is
p = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
p
came as C:\test
my file name is xyz.txt
i want to pass the the argument to the function as C:\test\xyz.txt
how can i combine path and file name
i tried below code
path = p & "xyz.txt"
can any one help me how can join the path and file name.
path. join() method in Python join one or more path components intelligently. This method concatenates various path components with exactly one directory separator ('/') following each non-empty part except the last path component.
Click the Start button and then click Computer, click to open the location of the desired file, hold down the Shift key and right-click the file. Copy As Path: Click this option to paste the full file path into a document. Properties: Click this option to immediately view the full file path (location).
Combines two strings into a path. Combine(String, String, String) Combines three strings into a path. Combine(String, String, String, String) Combines four strings into a path.
You can combine paths by using the resolve method.
You can use string concatenation to build a path. The correct way to do it, however, is to use the FileSystemObject's BuildPath()
method, because this will do the right thing with the backslashes under all circumstances.
Set FSO = CreateObject("Scripting.FileSystemObject")
scriptPath = FSO.GetParentFolderName(WScript.ScriptFullName)
textFilePath = FSO.BuildPath(scriptPath, "xyz.txt")
MsgBox textFilePath
Try like this code :
Option Explicit
Msgbox GetFilePath("xyz.txt")
'******************************************************
Function GetFilePath(FileName)
Dim fso,scriptPath
Set fso = CreateObject("Scripting.FileSystemObject")
scriptPath = FSO.GetParentFolderName(WScript.ScriptFullName)
GetFilePath = FSO.BuildPath(scriptPath,FileName)
End Function
'******************************************************
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