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.
Who is Participating?
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
you might not like "my style", but this way, you found it yourself, and you will be able to remind of it later...

anyhow, to avoid the "createobject", you need to add this in the project references:
Microsoft Scripting Runtime

once you checked that, you can do:
Dim fso as new Scripting.FileSystemObject
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Samuel-AMCAuthor Commented:
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?
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Samuel-AMCAuthor Commented:
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.
Samuel-AMCAuthor Commented:
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]Billing EngineerCommented:
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.
Samuel-AMCAuthor Commented:
Run-time error '424':
Object required

Could not find any references to scripting object in VB
Samuel-AMCAuthor Commented:
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
Samuel-AMCAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.