Solved

VB6 Get Path of a file

Posted on 2012-12-26
9
1,535 Views
Last Modified: 2012-12-26
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.
0
Comment
Question by:Samuel-AMC
  • 6
  • 3
9 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38721890
0
 

Author Comment

by:Samuel-AMC
ID: 38722043
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?
0
 

Author Comment

by:Samuel-AMC
ID: 38722310
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.
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

Author Comment

by:Samuel-AMC
ID: 38722535
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 ]
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38722793
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.
0
 

Author Comment

by:Samuel-AMC
ID: 38722840
Run-time error '424':
Object required

Could not find any references to scripting object in VB
0
 

Author Comment

by:Samuel-AMC
ID: 38722856
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
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 38722864
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
0
 

Author Closing Comment

by:Samuel-AMC
ID: 38722890
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.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question