Solved

VB6 Get Path of a file

Posted on 2012-12-26
9
1,499 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Window placement 17 75
Determine Range to Select 5 42
Convert VB6 MSXML2.ServerXMLHTTP process to C# 2 41
Added a column screws up code 5 49
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

910 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

23 Experts available now in Live!

Get 1:1 Help Now