Solved

VB6 Get Path of a file

Posted on 2012-12-26
9
1,470 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
 

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now