Avatar of Samuel-AMC
 asked on

VB6 Get Path of a file

Hello Everyone,

I'm working on a small project in which I would like to get the path of the file
I drag and drop into a textbox I have in my project form, the idea is to get the
file path and the file name in the textbox, but then I need only the path of the
file without the name of the file, but I do need the full path alone with the file.
Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1 = Data.Files(1)
End Sub

Open in new window

Then when I drag and drop a file into the textbox, I get the full path of the file
alone with the file name, comething like this: C:\Users\Samuel\Desktop\File.exe
But then I need a separate textbox or anything in which I could get only the path
of that file, which is something like this: C:\Users\Samuel\Desktop
But again, I also need the path with the full path and file name.

My project is a tool that when ever I drag and drop a file into it, automatically
generate and create a resource file from that file, so for now my project creates
that resource file in my tool folder, now the idea is to create the resource file
where the file is instead of creating this resource file in my tool folder.

Any help will be very appreciate, thanks.
Visual Basic Classic

Avatar of undefined
Last Comment

8/22/2022 - Mon
Guy Hengel [angelIII / a3]


Hi Angel,

Both links, one say ASP the other one VBScript, no problem, now here is the thing...
My Form have only one object which is a Texbox, then the path I need for the RES file
to be created is not from my VB App, it have to be right from the textbox in my Form.

set f=fs.GetFile("Text1.Text") ?????

Should this do the trick?

Don't know if you already read my reply, but what I really need is for the path to be
generate in a second textbox2 at the same time that I drop the file into the textbox1.

Textbox1 [ C:\Users\Samuel\Desktop\File.exe ]
Textbox2 [ C:\Users\Samuel\Desktop ]

Then be able to use the path from textbox2 to save the res file on that root path.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes

I have no problem getting the path of the file since I am the one draging the file
into the textbox, then when I do that the path is right there in the textbox1 field.
Actually what I need is the path of that same textbox1 to be added to the textbox2
But only the path without the file name.

For example:
Textbox1 [ C:\Users\Samuel\Desktop\File.exe ]
Textbox2 [ C:\Users\Samuel\Desktop ]
Guy Hengel [angelIII / a3]

this would be the code:
set f=fs.GetFile(Text1.Text)
Text2.Text = f.Path

and that the links are asp and vbscript are not an issue, the scripting objects are available in VB also.

Run-time error '424':
Object required

Could not find any references to scripting object in VB
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.

Never mind Angel, I found a better solution, this is my VB code now:

Dim strFullFilePath As String
strFullFilePath = Text1.Text
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Text2 = fso.GetParentFolderName(strFullFilePath)

And it doesn't need no references, thanks anyway.
I wish Ark were here, he would it give the code at once, like he did early today,
You are just like Idle_Mind
Guy Hengel [angelIII / a3]

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.

Okay thanks Angel, you the one who knows better, but to be honest, I've been using
Visual Basic 6 for a very long time, but I am only a user of the program nothing more,
so I'm not a programmer nor an expert, but every time I ask a question here, I always
expect experts to give me the code or the solution to my question, thats the reason
I become a member of EE, I know that I should't ask for the code since nobody will be
willing to do my home work, but I always try my best, but thats the true.