Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file handling 2

Status
Not open for further replies.

slowATthought

Programmer
Dec 2, 2003
56
US
I hardly know anything about file handling, and unfortunately, it is very important to know. I had several questions specifically, but any file handling information would be helpful.

I would like to do a for-each-next loop for each file in a certain directory.

Also, I would like to be able to open Internet Explorer to a web adress or to any directory on the computer.

Another helpful thing would be a function to return what drive letter is the user's hard drive.. maybe an API?

Thanks for any help

 
file handling can be accessed using the fileSystemObject. Firstly, add a reference to Microsoft Scripting Runtime.

Then

dim fso as new filesystemobject

you can then find the drive letter/type/size of any file. Search this forum for fso for more examples.

I'm sure LPlates will post with something to say fso is the spawn of the devil, but it will do you for a starter. It is just down to personal preference.

For internet explorer use the following:

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Sub LaunchExplorer_Click()
ShellExecute Me.hwnd, "Open", " vbNullString, App.Path, vbNormalFocus
End Sub

You need to have a button called launchExplorer and your away.

Good luck

BB
 
Heres a simple routine to loop thru each file in a folder, example uses c:\ as required folder. Hidden files won't be shown.

Dim fname As String

fname = Dir("c:\*.*")

Do Until fname = ""
Debug.Print "file : " & "c:\" & fname
fname = Dir()
Loop

 
BiggerBrother,
I used the API and it worked beautifully! I haven't run into an error with it yet. I even am able to shell a specific document through "notepad" instead of just opening the program. (i.e. Shell "notepad.exe")

SonOfEmidec1100,
Thanks for the reply! It worked, although I'm not exactly sure how... anyway, it does what I want with very little code, so its good.

Thanks both of you. Now I can work on some install programs! FUN! (note the sarcasm...)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top